From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Philip Semanchuk <philip@americanefficient.com>
Cc: PostgreSQL General <pgsql-general@lists.postgresql.org>
Subject: Re: psql syntax for array of strings in a variable?
Date: Fri, 29 Oct 2021 14:05:24 -0400
Message-ID: <714331.1635530724@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwYbiEwY0RAptgfYCKOb-fbC3Ddsph17Mnp6B==w6fRcaQ@mail.gmail.com>
References: <8A98A8A6-7AFE-42C8-884B-984323381269@americanefficient.com>
<CAKFQuwYbiEwY0RAptgfYCKOb-fbC3Ddsph17Mnp6B==w6fRcaQ@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Friday, October 29, 2021, Philip Semanchuk <philip@americanefficient.com>
> wrote:
>> I would appreciate help with the syntax for querying an array of strings
>> declared as a psql variable. Here's an example.
>>
>> \set important_days ARRAY['monday', 'friday']
> Not sure why the single quotes are getting stripped out but that is the
> issue. Maybe double them up to escape them like in a normal text literal?
Yeah, that's just the way that \set works (and most other psql backslash
commands, I believe). You've likely got an issue with whitespace
disappearing, too, though that might be harmless in this specific example.
regression=# \set foo 'bar baz'
regression=# \echo :foo
bar baz
regression=# \set foo 'bar ''baz'
regression=# \echo :foo
bar 'baz
regression=# \set foo bar ''baz
regression=# \echo :foo
barbaz
Not sure offhand how well-documented this is.
regards, tom lane
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, philip@americanefficient.com
Subject: Re: psql syntax for array of strings in a variable?
In-Reply-To: <714331.1635530724@sss.pgh.pa.us>
References: <8A98A8A6-7AFE-42C8-884B-984323381269@americanefficient.com> <CAKFQuwYbiEwY0RAptgfYCKOb-fbC3Ddsph17Mnp6B==w6fRcaQ@mail.gmail.com> <714331.1635530724@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox