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

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Philip Semanchuk <philip(at)americanefficient(dot)com>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: psql syntax for array of strings in a variable?
Date: 2021-10-29 17:34:42
Message-ID: CAKFQuwYbiEwY0RAptgfYCKOb-fbC3Ddsph17Mnp6B==w6fRcaQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday, October 29, 2021, Philip Semanchuk <philip(at)americanefficient(dot)com>
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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Pavel Stehule 2021-10-29 17:52:30 Re: psql syntax for array of strings in a variable?
Previous Message Oleg Serov 2021-10-29 17:22:56 Question: Is it possible to get the new xlog position after query execution?