From: Christoph Berg <christoph.berg@credativ.de>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #9198: psql -c 'SET; ...' not working
Date: Thu, 13 Feb 2014 14:18:58 +0100
Message-ID: <20140213131858.GB25703@msgid.credativ.de> (raw)
In-Reply-To: <25094.1392219652@sss.pgh.pa.us>
References: <20140212125626.2710.94912@wrigleys.postgresql.org>
<25094.1392219652@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
Re: Tom Lane 2014-02-12 <25094.1392219652@sss.pgh.pa.us>
> The reason this isn't a bug is that a -c command string is sent to the
> server as a single statement (PQexec call), and what "statement timeout"
> controls is the total time for the whole thing. The SET operation can't
> change the already-running timer for the current statement. It would
> affect the timeout for the next statement ... but there won't be one.
>
> Many people have complained that it's unintuitive that -c works this way
> rather than breaking up the string into multiple submissions the same way
> psql would do with normal input. We're afraid to change it for fear of
> breaking applications, though. If you want behavior more like psql's
> normal operation, consider
>
> echo "SET statement_timeout = '3s'; SELECT pg_sleep(2)" | psql
I think the docs don't really say that. The psql manpage says "single
transaction", but the problem here is rather "single command". I see
that "fixing" this would break the "one transaction" part, so it's
going to stay that way, but I'd propose something like this doc
update:
inline patch 1: doc/src/sgml/ref/psql-ref.sgml (+6/-1 lines) download inline-1.patch*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
*************** PostgreSQL documentation
*** 100,106 ****
string to divide it into multiple transactions. This is
different from the behavior when the same string is fed to
<application>psql</application>'s standard input. Also, only
! the result of the last SQL command is returned.
</para>
</listitem>
</varlistentry>
--- 100,111 ----
string to divide it into multiple transactions. This is
different from the behavior when the same string is fed to
<application>psql</application>'s standard input. Also, only
! the result of the last SQL command is returned. <command>SET</>
! commands that modify statement behavior will be ineffective because
! they are part of the already running statement. Most notably,
! <literal>psql -c 'SET statement_timeout = 0; SELECT ...'</literal>
! will not work as expected. (Use <literal>echo '...' | psql</literal>
! as above instead.)
</para>
</listitem>
</varlistentry>
I'm actually unsure if there's more SETs that have this surprising
behavior, if statement_timeout is the only one, psql(1) should mention
that instead of what I wrote in the patch.
Mit freundlichen Grüßen,
Christoph Berg
--
Senior Berater, Tel.: +49 (0)21 61 / 46 43-187
credativ GmbH, HRB Mönchengladbach 12080, USt-ID-Nummer: DE204566209
Hohenzollernstr. 133, 41061 Mönchengladbach
Geschäftsführung: Dr. Michael Meskes, Jörg Folz, Sascha Heuer
pgp fingerprint: 5C48 FE61 57F4 9179 5970 87C6 4C5A 6BAB 12D2 A7AE
Attachments:
signature.asc (application/pgp-signature, 818B) download
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: christoph.berg@credativ.de, tgl@sss.pgh.pa.us
Subject: Re: BUG #9198: psql -c 'SET; ...' not working
In-Reply-To: <20140213131858.GB25703@msgid.credativ.de>
References: <20140212125626.2710.94912@wrigleys.postgresql.org> <25094.1392219652@sss.pgh.pa.us> <20140213131858.GB25703@msgid.credativ.de>
* 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