public inbox for [email protected]
help / color / mirror / Atom feedFrom: Daniel Verite <[email protected]>
To: Jiří Fejfar <[email protected]>
Cc: [email protected]
Subject: Re: variable filename for psql \copy
Date: Mon, 25 Apr 2022 12:24:47 +0200
Message-ID: <[email protected]> (raw)
In-Reply-To: <CA+8wVNX6WgxgUxPFka=Ob-OQhOZVg0XM-NYqwHa5KTFr38JEJw@mail.gmail.com>
Jiří Fejfar wrote:
> I have found maybe buggy behaviour (of psql parser?) when using psql \copy
> with psql variable used for filename.
While it's annoying that it doesn't work as you tried it, this behavior is
documented, so in that sense it's not a bug.
The doc also suggests a workaround in a tip section:
From psql manpage:
The syntax of this command is similar to that of the SQL COPY
command. All options other than the data source/destination are as
specified for COPY. Because of this, special parsing rules apply to
the \copy meta-command. Unlike most other meta-commands, the entire
remainder of the line is always taken to be the arguments of \copy,
and neither variable interpolation nor backquote expansion are
performed in the arguments.
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/
Twitter: @DanielVerite
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: variable filename for psql \copy
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox