postgres DML操作并返回结果

insert操作并返回结果

imos=#  CREATE TABLE person (
imos(#       id   SERIAL,
imos(#       name TEXT
imos(#    );
CREATE TABLE
imos=#
imos=#
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
 id
----
  1
(1 row)

INSERT 0 1
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING id;
 id
----
  2
(1 row)

INSERT 0 1
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING *;
 id |     name
----+---------------
  3 | Blaise Pascal
(1 row)

INSERT 0 1
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') RETURNING null;
 ?column?
----------

(1 row)

INSERT 0 1
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') ;
INSERT 0 1

delete 操作并返回结果

imos=# select * from person;
 id |     name
----+---------------
  1 | Blaise Pascal
  2 | Blaise Pascal
  3 | Blaise Pascal
  4 | Blaise Pascal
  5 | Blaise Pascal
(5 rows)

imos=# delete from person where id=1;
DELETE 1
imos=# select * from person;
 id |     name
----+---------------
  2 | Blaise Pascal
  3 | Blaise Pascal
  4 | Blaise Pascal
  5 | Blaise Pascal
(4 rows)

imos=# delete from person where id=2 returning *;
 id |     name
----+---------------
  2 | Blaise Pascal
(1 row)

DELETE 1
imos=# delete from person where id=3 returning null;
 ?column?
----------

(1 row)

DELETE 1
imos=# select * from person;
 id |     name
----+---------------
  4 | Blaise Pascal
  5 | Blaise Pascal
(2 rows)

imos=# delete from person where id=4 returning name;
     name
---------------
 Blaise Pascal
(1 row)

DELETE 1
imos=# delete from person where id=5 returning id;
 id
----
  5
(1 row)

DELETE 1
imos=# select * from person;
 id | name
----+------
(0 rows)

update操作并返回结果

imos=# select * from person;
 id | name
----+------
(0 rows)

imos=#
imos=#
imos=#
imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal') ;
INSERT 0 1
imos=# select * from person;
 id |     name
----+---------------
  6 | Blaise Pascal
(1 row)

imos=#    INSERT INTO person (name) VALUES ('Blaise Pascal32') ;
INSERT 0 1
imos=# select * from person;
 id |      name
----+-----------------
  6 | Blaise Pascal
  7 | Blaise Pascal32
(2 rows)

imos=# update person set name='test' where id=6 returning *;
 id | name
----+------
  6 | test
(1 row)

UPDATE 1
imos=# select * from person;
 id |      name
----+-----------------
  7 | Blaise Pascal32
  6 | test
(2 rows)

imos=# update person set name='test' where id=7 returning name;
 name
------
 test
(1 row)

UPDATE 1
imos=# select * from person;
 id | name
----+------
  6 | test
  7 | test
(2 rows)

posted @   岳麓丹枫  阅读(262)  评论(0编辑  收藏  举报
编辑推荐:
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
阅读排行:
· Spring AI + Ollama 实现 deepseek-r1 的API服务和调用
· 《HelloGitHub》第 106 期
· 数据库服务器 SQL Server 版本升级公告
· 深入理解Mybatis分库分表执行原理
· 使用 Dify + LLM 构建精确任务处理应用
点击右上角即可分享
微信分享提示