Re: Alternative to \copy in psql modelled after \g
Fabien COELHO <coelho@cri.ensmp.fr>
From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Daniel Verite <daniel@manitou-mail.org>
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-20T14:48:14Z
Lists: pgsql-hackers
>>> I understand from the code that the COPY is really executed, so the ERROR
>>> and so ROW_COUNT about the SQL should reflect that. Basically the change
>>> makes the client believe that there is an SQL error whereas the error is
>>> on the client.
>>
>> Right, but wether COPY fails because psql can't write the output,
>> possibly half-way because of a disk full condition, or because the
>> query was cancelled or the server went down, are these distinctions
>> meaningful for a script?
>
> It could if the SQL command has side effects, but probably this does not
> apply to COPY TO which cannot have.
Yes it can:
COPY (
UPDATE pgbench_branches
SET bbalance = bbalance + 1
WHERE bid <= 5
RETURNING *) TO STDOUT \g /BAD
The SQL command is executed but the backslash command fails.
--
Fabien.
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