Re: Add partial :-variable expansion to psql \copy
Corey Huinker <corey.huinker@gmail.com>
From: Corey Huinker <corey.huinker@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Fabien COELHO <coelho@cri.ensmp.fr>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-03-31T15:53:02Z
Lists: pgsql-hackers
>
> Anyway, my feeling about it is that \copy parsing is a huge hack
> right now, and I'd rather see it become less of a hack, that is
> more like other psql commands, instead of getting even hackier.
>
I wasn't as horrified as Tom, but it did have the feeling of it solving
half the problem.
We can already do this
COPY (SELECT :foo FROM :bar WHERE :condition) TO STDOUT \g :"myfilename"
So it seems that what we need is a good way to pipe local data to a
standard COPY command, which is then free to use the existing variable
interpolations.
If we could do this:
COPY :"myschema".:"mytable" FROM STDIN \g < :"myfilename"
that would fit our patterns most cleanly, but we would probably create a
parsing hassle for ourselves if we ever wanted to mix pipe-to with
pipe-from. It would also require checking on every command, when uploaded
\copy commands make up a very small percentage of commands issued. So I
don't think there's a good way around the asymmetry of COPY TO being a
regular \g-able command, whereas COPY FROM will always require some other
send-command.
Perhaps we create a new command \copyfrom:
COPY :"myschema".:"mytable" :options FROM STDIN \copyfrom :"myfilename"
COPY :"myschema".:"mytable" :options FROM STDIN \copyfrom
:"my_complex_command" |
If we had something like that we might be able to replace all existing uses
of \copy.
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix psql's "\g target" meta-command to work with COPY TO STDOUT.
- 6d3ede5f1c65 12.0 cited