pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: christoph.berg@credativ.de
Subject: BUG #17504: psql --single-transaction -vON_ERROR_STOP=1 still commits after client-side error
Date: Mon, 30 May 2022 14:59:24 +0000
Message-ID: <17504-76b68018e130415e@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      17504
Logged by:          Christoph Berg
Email address:      christoph.berg@credativ.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



view thread (22+ messages)  latest in thread

Message-ID: <17504-76b68018e130415e@postgresql.org>
Permalink:  ../17504-76b68018e130415e@postgresql.org/
Also on:    postgresql.org/message-id/17504-76b68018e130415e@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, christoph.berg@credativ.de
  Subject: Re: BUG #17504: psql --single-transaction -vON_ERROR_STOP=1 still commits after client-side error
  In-Reply-To: <17504-76b68018e130415e@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox