做“\复制"postgres 中的命令处理提交和回滚? [英] does "\copy" command handle commit and rollback in postgres?

查看:70
本文介绍了做“\复制"postgres 中的命令处理提交和回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 psql 执行 .sql 文件.我在里面运行 .sql 文件,我编写了以下查询 \copy table name from .dumb.所以如果命令失败,它会默认处理提交/回滚.或者我们需要解决这个问题.

I am trying execute .sql file with psql. I run .sql file inside i have written following query \copy table name from .dumb. So if the command fails, will it handle commit/rollback by default. or we need to take care of that.

推荐答案

如果 \copy 失败,事务将被中止,示例如下:

If \copy fails transaction will be aborted, here is example:

t=# \! cat s07
create table trans(i int);
copy s07 from '/no such file';
t=# begin;
BEGIN
t=# \i s07
CREATE TABLE
psql:s07:2: ERROR:  could not open file "/no such file" for reading: No such file or directory
t=# select * from trans;
ERROR:  current transaction is aborted, commands ignored until end of transaction block
t=# end;
ROLLBACK

这篇关于做“\复制"postgres 中的命令处理提交和回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆