Search Postgresql Archives

Re: psql syntax for array of strings in a variable?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Friday, October 29, 2021, Philip Semanchuk <philip@xxxxxxxxxxxxxxxxxxxxx> wrote:
Hi,
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?

Otherwise consider just doing a comma delimited string and using string_to_array in the sql to turn it into an array at runtime.
 


\set important_days ARRAY['monday',
                          'friday']

Not with \set.  You could write sql to output the text and then execute it using \gexec to store the column value in a variable.  That too may be a solution to the missing single quotes.

David J.
 

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux