sql returning

阅读 68

2022-07-18

在​​INSERT​​ INTO或者UPDATE的时候在最后面加上RETURNING colname,PostgreSQL会在插入或者更新数据之后会返回你指定的字段

postgres=# insert into tb3(name) values('aa')returning name;
name
------
aa
(1 row)

INSERT 0 1
postgres=# insert into tb3(name) values('aa')returning id;
id
----
2
(1 row)

INSERT 0 1
postgres=# insert into tb3(name) values('aa')returning id,name;
id | name
----+------
3 | aa
(1 row)

INSERT 0 1

 

精彩评论(0)

0 0 举报