BUG #17504: psql --single-transaction -vON_ERROR_STOP=1 still commits after client-side error

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: christoph(dot)berg(at)credativ(dot)de
Subject: BUG #17504: psql --single-transaction -vON_ERROR_STOP=1 still commits after client-side error
Date: 2022-05-30 14:59:24
Message-ID: 17504-76b68018e130415e@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17504
Logged by: Christoph Berg
Email address: christoph(dot)berg(at)credativ(dot)de
PostgreSQL version: 14.3
Operating system: any
Description:

A customer is reporting the following script has not the intended effect:

Preparation:
psql -c 'create table bar (id int)'
psql -c 'insert into bar values(1)'
-- bar now contains "1"

Test script truncate-and-copy.sql:
truncate bar;
\copy bar from bar.txt
select * from bar;

psql --single-transaction -vON_ERROR_STOP=1 -Xf truncate-and-copy.sql
TRUNCATE TABLE
psql:truncate-and-copy.sql:2: error: bar.txt: No such file or directory

The last "select" is correctly not executed anymore, i.e. the script
execution is correcty aborted, but bar is now empty, i.e. `psql -1` did
commit even when the script was erroring out:
psql -c 'select * from bar'
id
────
(0 rows)

The expectation would be that the script is either fully committed, or not
at all.

The problem is not limited to \copy; \i has the same problem.
A workaround is to drop -1, and use an explicit transaction in the script.

Christoph

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Christoph Berg 2022-05-30 15:18:28 Re: BUG #17504: psql --single-transaction -vON_ERROR_STOP=1 still commits after client-side error
Previous Message Alvaro Herrera 2022-05-30 14:11:39 Re: BUG #17485: Records missing from Primary Key index when doing REINDEX INDEX CONCURRENTLY