做“\ copy”命令处理提交和回滚在postgres?

问题描述:

我试图用psql执行.sql文件。我运行.sql文件里面我写了以下查询\copy table name from .dumb。所以如果命令失败,它会默认处理提交/回滚。或者我们需要照顾这一点。做“ copy”命令处理提交和回滚在postgres?

+0

请编辑您问:你想运行SQL文件或从file'?.. –

如果\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 
+0

'\复制表谢谢,,,所以无需手动处理。 – Shashi

+0

你如何手动处理提交?.. –

+0

那么什么是提交行为。 – Shashi

一切都取决于你正在运行PG的版本。因为psql的默认是自动提交。而在更新的版本中,您无法将其关闭。所以每个成功的手动发布的COPY或\ copy命令都会立即提交。