Re: psql syntax for array of strings in a variable? - Mailing list pgsql-general

From Tom Lane
Subject Re: psql syntax for array of strings in a variable?
Date
Msg-id 714331.1635530724@sss.pgh.pa.us
Whole thread Raw
In response to Re: psql syntax for array of strings in a variable?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Responses Re: psql syntax for array of strings in a variable?
List pgsql-general
"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



pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: psql syntax for array of strings in a variable?
Next
From: Philip Semanchuk
Date:
Subject: Re: psql syntax for array of strings in a variable?