pgsql: Prevent "\g filename" from affecting subsequent commands after a

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Prevent "\g filename" from affecting subsequent commands after a
Date: 2013-02-02 19:22:35
Message-ID: E1U1ifb-0003uQ-9Y@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Prevent "\g filename" from affecting subsequent commands after an error.

In the previous coding, psql's state variable saying that output should
go to a file was only reset after successful completion of a query
returning tuples. Thus for example,

regression=# select 1/0
regression-# \g somefile
ERROR: division by zero
regression=# select 1/2;
regression=#

... huh, I wonder where that output went. Even more oddly, the state
was not reset even if it's the file that's causing the failure:

regression=# select 1/2 \g /foo
/foo: Permission denied
regression=# select 1/2;
/foo: Permission denied
regression=# select 1/2;
/foo: Permission denied

This seems to me not to satisfy the principle of least surprise.
\g is certainly not documented in a way that suggests its effects are
at all persistent.

To fix, adjust the code so that the flag is reset at exit from SendQuery
no matter what happened.

Noted while reviewing the \gset patch, which had comparable issues.
Arguably this is a bug fix, but I'll refrain from back-patching for now.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/101d6ae755656b675b7c18db655249511982b780

Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml | 10 +++++++---
src/bin/psql/command.c | 2 +-
src/bin/psql/common.c | 32 +++++++++++++++++++-------------
3 files changed, 27 insertions(+), 17 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Robert Haas 2013-02-02 19:55:10 Re: pgsql: Mark vacuum_defer_cleanup_age as PGC_POSTMASTER.
Previous Message Simon Riggs 2013-02-02 18:55:31 pgsql: Mark vacuum_defer_cleanup_age as PGC_POSTMASTER.