欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > PG psql --single-transaction 参数功能

PG psql --single-transaction 参数功能

2025/4/22 3:32:10 来源:https://blog.csdn.net/yueludanfeng/article/details/147366140  浏览:    关键词:PG psql --single-transaction 参数功能

文章目录

  • PG psql --single-transaction 参数功能

PG psql --single-transaction 参数功能

  • test.sql 文件
create table test1(id int);
CREATE OR REPLACE FUNCTION func_test() 
RETURNS INTEGER AS
$BODY$
BEGINxxxreturn 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;CREATE OR REPLACE FUNCTION func_test2() 
RETURNS INTEGER AS
$BODY$
BEGINperform func_test();return 0;
END;
$BODY$
LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER;
select * from func_test2();
create table test2(id int);
  • 演示
[root@node101 test]# /home/postgres/pgsql/bin/psql -Upostgres  -f test.sql --single-transaction
CREATE TABLE
psql:test.sql:11: ERROR:  syntax error at or near "xxx"
LINE 6: xxx^
psql:test.sql:22: ERROR:  current transaction is aborted, commands ignored until end of transaction block
psql:test.sql:23: ERROR:  current transaction is aborted, commands ignored until end of transaction block
psql:test.sql:24: ERROR:  current transaction is aborted, commands ignored until end of transaction block
[root@node101 liwenbin]# psql -Upostgres
psql (11.8)
Type "help" for help.postgres=# \dfList of functionsSchema | Name | Result data type | Argument data types | Type 
--------+------+------------------+---------------------+------
(0 rows)postgres=# \dt
Did not find any relations.
postgres=# \q

可以看到, 只要中途报错, 就会回滚到最初始状态

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词