pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
5+ messages / 4 participants
[nested] [flat]
* BUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
@ 2011-07-13 20:53 Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2011-07-14 02:10 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Craig Ringer <craig@postnewspapers.com.au>
0 siblings, 1 reply; 5+ messages in thread
From: Aleksey Tsalolikhin @ 2011-07-13 20:53 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged online:
Bug reference: 6117
Logged by: Aleksey Tsalolikhin
Email address: atsaloli.tech@gmail.com
PostgreSQL version: 8.4.8
Operating system: CentOS 5.5 (64-bit)
Description: psql -c does not work as expected. a documentation bug?
a program bug?
Details:
The psql man page says, in the section for the -c option:
If the command string contains multiple SQL
commands, they are processed in a single
transaction
However when I run a command string with multiple
SQL commands, apparently only the last one is
processed.
For example:
# psql -U postgres -c "select now(); select now(); select version();"
version
----------------------------------------------------------------------------
--------------------------------------
PostgreSQL 8.4.8 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC)
4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit
(1 row)
#
Yet this works fine:
# echo "select now(); select now(); select version();"|psql -f- -U postgres
now
-------------------------------
2011-07-13 13:51:01.594725-07
(1 row)
now
-------------------------------
2011-07-13 13:51:01.597903-07
(1 row)
version
----------------------------------------------------------------------------
--------------------------------------
PostgreSQL 8.4.8 on x86_64-redhat-linux-gnu, compiled by GCC gcc (GCC)
4.1.2 20080704 (Red Hat 4.1.2-48), 64-bit
(1 row)
#
This is what I expect to see.
Could you please fix psql or make the documentation for the -c option more
clear?
Thanks very much and thanks for a great product!
Yours truly,
Aleksey
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
2011-07-13 20:53 BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
@ 2011-07-14 02:10 ` Craig Ringer <craig@postnewspapers.com.au>
2011-07-14 15:34 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Tom Lane <tgl@sss.pgh.pa.us>
2012-08-03 18:03 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Bruce Momjian <bruce@momjian.us>
0 siblings, 2 replies; 5+ messages in thread
From: Craig Ringer @ 2011-07-14 02:10 UTC (permalink / raw)
To: Aleksey Tsalolikhin <atsaloli.tech@gmail.com>; +Cc: pgsql-bugs
On 14/07/2011 4:53 AM, Aleksey Tsalolikhin wrote:
> The following bug has been logged online:
>
> Bug reference: 6117
> Logged by: Aleksey Tsalolikhin
> Email address: atsaloli.tech@gmail.com
> PostgreSQL version: 8.4.8
> Operating system: CentOS 5.5 (64-bit)
> Description: psql -c does not work as expected. a documentation bug?
> a program bug?
> Details:
>
> The psql man page says, in the section for the -c option:
>
> If the command string contains multiple SQL
> commands, they are processed in a single
> transaction
>
> However when I run a command string with multiple
> SQL commands, apparently only the last one is
> processed.
>
What's happening is that all of them are processed, but only the output
for the last one is emitted. I agree that the documentation isn't clear
about that, and I'm not sure whether or not that was the intended result.
psql -c "CREATE TABLE test(x integer); INSERT INTO test(x) VALUES
(1),(2),(3); SELECT version(); SELECT * FROM test;"
x
---
1
2
3
(3 rows)
Comments anybody? Just fix the docs, or is this a behaviour issue?
--
Craig Ringer
POST Newspapers
276 Onslow Rd, Shenton Park
Ph: 08 9381 3088 Fax: 08 9388 2258
ABN: 50 008 917 717
http://www.postnewspapers.com.au/
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
2011-07-13 20:53 BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2011-07-14 02:10 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Craig Ringer <craig@postnewspapers.com.au>
@ 2011-07-14 15:34 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-07-14 18:24 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
1 sibling, 1 reply; 5+ messages in thread
From: Tom Lane @ 2011-07-14 15:34 UTC (permalink / raw)
To: Craig Ringer <craig@postnewspapers.com.au>; +Cc: Aleksey Tsalolikhin <atsaloli.tech@gmail.com>; pgsql-bugs
Craig Ringer <craig@postnewspapers.com.au> writes:
> What's happening is that all of them are processed, but only the output
> for the last one is emitted. I agree that the documentation isn't clear
> about that, and I'm not sure whether or not that was the intended result.
> ...
> Comments anybody? Just fix the docs, or is this a behaviour issue?
This is a byproduct of the fact that psql shoves the -c string out to
the backend as a single Query message, rather than splitting it at
semicolons and sending each command individually, which is what would
happen if you typed a multi-command line normally.
That has a bunch of indirect semantic implications, like the commands
all being done in one transaction and execution of the whole thing
always being abandoned after the first error.
We've talked many times about changing that, but always been too afraid
of breaking user scripts that rely on the current behavior.
We could possibly address Aleksey's complaint without changing the
behavior otherwise, but I'm not sure it's worth the trouble. So I
vote for document-and-move-on.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
2011-07-13 20:53 BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2011-07-14 02:10 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Craig Ringer <craig@postnewspapers.com.au>
2011-07-14 15:34 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Tom Lane <tgl@sss.pgh.pa.us>
@ 2011-07-14 18:24 ` Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
0 siblings, 0 replies; 5+ messages in thread
From: Aleksey Tsalolikhin @ 2011-07-14 18:24 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Craig Ringer <craig@postnewspapers.com.au>; pgsql-bugs
Document-and-move-on sounds fine to me. Thank you!
Aleksey
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug?
2011-07-13 20:53 BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2011-07-14 02:10 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Craig Ringer <craig@postnewspapers.com.au>
@ 2012-08-03 18:03 ` Bruce Momjian <bruce@momjian.us>
1 sibling, 0 replies; 5+ messages in thread
From: Bruce Momjian @ 2012-08-03 18:03 UTC (permalink / raw)
To: Craig Ringer <craig@postnewspapers.com.au>; +Cc: Aleksey Tsalolikhin <atsaloli.tech@gmail.com>; pgsql-bugs
On Thu, Jul 14, 2011 at 10:10:28AM +0800, Craig Ringer wrote:
> On 14/07/2011 4:53 AM, Aleksey Tsalolikhin wrote:
> >The following bug has been logged online:
> >
> >Bug reference: 6117
> >Logged by: Aleksey Tsalolikhin
> >Email address: atsaloli.tech@gmail.com
> >PostgreSQL version: 8.4.8
> >Operating system: CentOS 5.5 (64-bit)
> >Description: psql -c does not work as expected. a documentation bug?
> > a program bug?
> >Details:
> >
> >The psql man page says, in the section for the -c option:
> >
> > If the command string contains multiple SQL
> > commands, they are processed in a single
> > transaction
> >
> >However when I run a command string with multiple
> >SQL commands, apparently only the last one is
> >processed.
> >
> What's happening is that all of them are processed, but only the
> output for the last one is emitted. I agree that the documentation
> isn't clear about that, and I'm not sure whether or not that was the
> intended result.
>
> psql -c "CREATE TABLE test(x integer); INSERT INTO test(x) VALUES
> (1),(2),(3); SELECT version(); SELECT * FROM test;"
> x
> ---
> 1
> 2
> 3
> (3 rows)
>
>
> Comments anybody? Just fix the docs, or is this a behaviour issue?
I have added documentation for this behavior. Patch attached, and
backpatched to 9.2 and 9.1.
--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com
+ It's impossible for everything to be true. +
Attachments:
psql.diff (text/x-diff, 980B) download
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
new file mode 100644
index b6bf6a3..1ba5ea8
*** a/doc/src/sgml/ref/psql-ref.sgml
--- b/doc/src/sgml/ref/psql-ref.sgml
*************** PostgreSQL documentation
*** 99,105 ****
<command>BEGIN</>/<command>COMMIT</> commands included in the
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.
</para>
</listitem>
</varlistentry>
--- 99,106 ----
<command>BEGIN</>/<command>COMMIT</> commands included in the
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>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2012-08-03 18:03 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-07-13 20:53 BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2011-07-14 02:10 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Craig Ringer <craig@postnewspapers.com.au>
2011-07-14 15:34 ` Tom Lane <tgl@sss.pgh.pa.us>
2011-07-14 18:24 ` Aleksey Tsalolikhin <atsaloli.tech@gmail.com>
2012-08-03 18:03 ` Re: BUG #6117: psql -c does not work as expected. a documentation bug? a program bug? Bruce Momjian <bruce@momjian.us>
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