修改postgresql的自动提交

来源:互联网 发布:vc mfc编程登录界面 编辑:程序博客网 时间:2024/05/29 05:00
默认,postgresql是自动提交的,可以避免自动提交  
1)使用begin;命令  
  示例:  
postgres=# begin;  
BEGIN  
postgres=# insert into test values(2,2);  
INSERT 0 1  
postgres=# select * from test;  
 id | name  
----+------  
  1 |  
  1 |    2  
  2 |    2  
(3 行记录)  
  
  
postgres=# rollback;  
ROLLBACK  
postgres=# select * from test;  
 id | name  
----+------  
  1 |  
  1 |    2  
(2 行记录)  
  
2)还可以直接关闭自动提交的功能  
\set AUTOCOMMIT off  
示例:  
postgres=# \set AUTOCOMMIT off  
postgres=#  
postgres=#  
postgres=# insert into test values(2,2);  
INSERT 0 1  
postgres=# select * from test;  
 id | name  
----+------  
  1 |  
  1 |    2  
  2 |    2  
(3 行记录)  
  
  
postgres=# rollback;  
ROLLBACK  
postgres=# select * from test;  
 id | name  
----+------  
  1 |  
  1 |    2  
(2 行记录)  
原创粉丝点击