Re: Alternative to \copy in psql modelled after \g
Daniel Verite <daniel@manitou-mail.org>
From: "Daniel Verite" <daniel@manitou-mail.org>
To: "Fabien COELHO" <coelho@cri.ensmp.fr>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>,"Alvaro Herrera"
<alvherre@2ndquadrant.com>,"PostgreSQL Hackers"
<pgsql-hackers@lists.postgresql.org>,"David G. Johnston"
<david.g.johnston@gmail.com>
Date: 2019-01-21T12:48:32Z
Lists: pgsql-hackers
Fabien COELHO wrote:
> sql> SELECT 1 \g /BAD
> /BAD: Permission denied
>
> sql> \echo :ERROR
> false
That seems broken, because it's pointless to leave out a class of errors
from ERROR. Presumably the purpose of ERROR is to enable
error checking like:
\if :ERROR
... error processing
\endif
Now if you download data with SELECT or COPY and we can't even
create the file, how is that a good idea to intentionally have the
script fail to detect it? What purpose does it satisfy?
> The documentation states that ERROR is about SQL, not psql internal stuff:
>
> ERROR true if the last SQL query failed, false if it succeeded.
> See also SQLSTATE.
ERROR is set by SetResultVariables(PGresult *results, bool success)
and takes the value of "success", ignoring the PGresult.
So why is ERROR independant of the SQL result, relatively to your
claim that it should never reflect anything else?
Best regards,
--
Daniel Vérité
PostgreSQL-powered mailer: http://www.manitou-mail.org
Twitter: @DanielVerite
Commits
-
Fix psql's "\g target" meta-command to work with COPY TO STDOUT.
- cda1e27fb706 9.5.16 landed
- ae4c7d5ab886 9.6.12 landed
- 8e97a97b3206 10.7 landed
- 6d3ede5f1c65 12.0 landed
- 2c50c9f23d1d 11.2 landed