当前位置: 首页 > news >正文

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

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

相关文章:

  • JavaScript 位掩码常量教程
  • Python range 使用详解
  • Oracle--用户管理
  • React 路由入门秘籍:BrowserRouter 的江湖之道
  • C++STL教程入门
  • python生成项目依赖文件requirements.txt
  • Rocky Linux 9.1 修改网卡和DNS
  • 操作系统中的虚拟化技术深度对话
  • 认知升级:把握人工智能教育化转型的历史机遇
  • trae海外版无限流白嫖指南,解决有限流,总提示在排队难题
  • 主机运行状态的监控命令(top命令)
  • React基础知识(补充中)
  • 19. git reflog
  • GIS开发笔记(9)结合osg及osgEarth实现三维球经纬网格绘制及显隐
  • Nginx静态资源跳转添加权限验证
  • optool为macho文件增加动态库
  • 从零创建 Docker 镜像(基于 OCI 格式)
  • Datawhale 春训营 创新药赛道
  • Linux 进程概念补充 (自用)
  • 代理模式(Proxy Pattern)
  • 中国泳协:新奥运周期竞争激烈,“三从一新”全力提升实力
  • 中国全国政协-越南祖国阵线中央暨边境省份组织第三次友好交流活动在南宁开幕
  • 大连万达商业管理集团提前兑付“22大连万达MTN001” ,本息2.64亿元
  • “代课老师被男友杀害案”一审开庭,将择期宣判
  • 用了半年的洗衣机竟比马桶还脏,别再这样洗衣服了
  • 江南大部、江淮南部等地今起有较强降雨,水利部部署防范工作