From: | "Daniel Verite" <daniel(at)manitou-mail(dot)org> |
---|---|
To: | "Christoph Berg" <myon(at)debian(dot)org> |
Cc: | Fabien Coelho <coelho(at)cri(dot)ensmp(dot)fr>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Add partial :-variable expansion to psql \copy |
Date: | 2025-04-01 12:06:28 |
Message-ID: | 6d505785-6faf-452e-8723-7300892ac08a@manitou-mail.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Christoph Berg wrote:
> Perhaps this form could be improved by changing `\copy (select) to file`
> to something like `select \gcopy (to file)`. That might make :expansion
> in the "select" part easier to handle.
In this direction (COPY TO), it was already taken care of by
commit 6d3ede5f1c654f923b2767b0b0c3b09569adaa18 [1]
a few years ago.
That is, the following sequence already works fine:
\set filename '/tmp/foo'
\set column relname
\set table pg_class
COPY (select :"column" from :"table") TO STDOUT \g :filename
It's also mentioned in the manual through that paragraph in \copy
"
Tip
Another way to obtain the same result as \copy ... to is to use the
SQL COPY ... TO STDOUT command and terminate it with \g filename or
\g |program. Unlike \copy, this method allows the command to span
multiple lines; also, variable interpolation and backquote expansion
can be used.
"
Best regards,
--
Daniel Vérité
https://postgresql.verite.pro/
From | Date | Subject | |
---|---|---|---|
Next Message | Alexander Korotkov | 2025-04-01 12:07:59 | Re: Replace IN VALUES with ANY in WHERE clauses during optimization |
Previous Message | Aleksander Alekseev | 2025-04-01 11:56:17 | Re: AIO v2.5 |