Re: Parser abort ignoring following commands - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Parser abort ignoring following commands
Date
Msg-id 22487.990889951@sss.pgh.pa.us
Whole thread Raw
In response to Parser abort ignoring following commands  (Peter Eisentraut <peter_e@gmx.net>)
Responses Re: Parser abort ignoring following commands  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Peter Eisentraut <peter_e@gmx.net> writes:
> psql -c 'select * from pg_class; select * from no_such_table;'
> Shouldn't this at least give me the result of the first select before
> aborting the second?

The behavior you are complaining of is not the backend's fault.
The reason it acts that way is that psql is feeding the entire -c 
string to the backend as one query, and not paying any attention
to the possibility that multiple query results might be available
from the string.

It's a little bit inconsistent that psql feeds a -c string to the
backend as one query, whereas the same input line fed to it from a file
or terminal would be split into per-statement queries.  However,
I'd vote against changing it, since (a) you might break existing
applications that depend on this behavior, and (b) if you do that then
there will be no way to exercise multi-statement query strings from
psql.

It might possibly make sense for psql to stop using PQexec() but
instead use PQsendQuery() and PQgetResult(), so that it could
handle multiple results coming back from a single query string.
If you did that then the first example would work the way you want.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: Parser abort ignoring following commands
Next
From: Peter Eisentraut
Date:
Subject: Re: Parser abort ignoring following commands