aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2013-02-02 14:21:24 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2013-02-02 14:22:17 -0500
commit101d6ae755656b675b7c18db655249511982b780 (patch)
treea70bcd51365be085c2c728d70c30de0456786cd8 /doc/src
parent84725aa5efe11688633b553e58113efce4181f2e (diff)
downloadpostgresql-101d6ae755656b675b7c18db655249511982b780.tar.gz
postgresql-101d6ae755656b675b7c18db655249511982b780.zip
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.
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ref/psql-ref.sgml10
1 files changed, 7 insertions, 3 deletions
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 4c87d8ad7fe..eb5e3b19048 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -1608,9 +1608,13 @@ Tue Oct 26 21:40:57 CEST 1999
optionally stores the query's output in <replaceable
class="parameter">filename</replaceable> or pipes the output
into a separate Unix shell executing <replaceable
- class="parameter">command</replaceable>. A bare
- <literal>\g</literal> is virtually equivalent to a semicolon. A
- <literal>\g</literal> with argument is a <quote>one-shot</quote>
+ class="parameter">command</replaceable>. The file or command is
+ written to only if the query successfully returns zero or more tuples,
+ not if the query fails or is a non-data-returning SQL command.
+ </para>
+ <para>
+ A bare <literal>\g</literal> is essentially equivalent to a semicolon.
+ A <literal>\g</literal> with argument is a <quote>one-shot</quote>
alternative to the <command>\o</command> command.
</para>
</listitem>