Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0a1e4f0

Browse files
committed
Fix psql's single transaction mode on client-side errors with -c/-f switches
psql --single-transaction is able to handle multiple -c and -f switchesin a single transaction sinced5563d7, but this had the surprisingbehavior of forcing a transaction COMMIT even if psql failed with anerror in the client (for example incorrect path given to \copy), whichwould generate an error, but still commit any changes that were alreadyapplied in the backend. This commit makes the behavior more consistent,by enforcing a transaction ROLLBACK if any commands fail, bothclient-side and backend-side, so as no changes are applied if one errorhappens in any of them.Some tests are added on HEAD to provide some coverage about all that.Backend-side errors are unreliable as IPC::Run can complain on SIGPIPEif psql quits before reading a query result, but that should workproperly in the case where any errors come from psql itself, which iswhat the original report is about.Reported-by: Christoph BergAuthor: Kyotaro Horiguchi, Michael PaquierDiscussion:https://postgr.es/m/17504-76b68018e130415e@postgresql.orgBackpatch-through: 10
1 parent34875f3 commit0a1e4f0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

‎doc/src/sgml/ref/psql-ref.sgml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,10 @@ EOF
592592
<application>psql</application> to issue a <command>BEGIN</command> command
593593
before the first such option and a <command>COMMIT</command> command after
594594
the last one, thereby wrapping all the commands into a single
595-
transaction. This ensures that either all the commands complete
596-
successfully, or no changes are applied.
595+
transaction. If any of the commands fails, a
596+
<command>ROLLBACK</command> command is sent instead. This ensures that
597+
either all the commands complete successfully, or no changes are
598+
applied.
597599
</para>
598600

599601
<para>

‎src/bin/psql/startup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,9 @@ main(int argc, char *argv[])
416416

417417
if (options.single_txn)
418418
{
419-
if ((res=PSQLexec("COMMIT"))==NULL)
419+
res=PSQLexec((successResult==EXIT_SUCCESS) ?
420+
"COMMIT" :"ROLLBACK");
421+
if (res==NULL)
420422
{
421423
if (pset.on_error_stop)
422424
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp