“\copy”命令在 postgres 中处理提交和回滚吗?
does "\copy" command handle commit and rollback in postgres?
我正在尝试使用 psql
执行 .sql 文件。我在 运行 .sql 文件中编写了以下查询 \copy table name from .dumb
。所以如果命令失败,它会默认处理 commit/rollback 吗?或者我们需要处理它。
如果\copy
失败交易将中止,这里是例子:
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
一切都取决于您使用的 PG 版本 运行。因为 psql 的默认设置是自动提交。在较新的版本中,您无法将其关闭。因此,每个成功的手动发出的 COPY 或 \copy 命令都会立即提交。
我正在尝试使用 psql
执行 .sql 文件。我在 运行 .sql 文件中编写了以下查询 \copy table name from .dumb
。所以如果命令失败,它会默认处理 commit/rollback 吗?或者我们需要处理它。
如果\copy
失败交易将中止,这里是例子:
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
一切都取决于您使用的 PG 版本 运行。因为 psql 的默认设置是自动提交。在较新的版本中,您无法将其关闭。因此,每个成功的手动发出的 COPY 或 \copy 命令都会立即提交。