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

From Philip Semanchuk
Subject psql syntax for array of strings in a variable?
Date
Msg-id 8A98A8A6-7AFE-42C8-884B-984323381269@americanefficient.com
Whole thread Raw
Responses Re: psql syntax for array of strings in a variable?
Re: psql syntax for array of strings in a variable?
List pgsql-general
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']

select 1 where 'monday' = ANY(:important_days);
ERROR:  42703: column "monday" does not exist
LINE 1: select 1 where 'monday' = ANY(ARRAY[monday,friday]);

select 1 where 'monday' = ANY(:"important_days");
ERROR:  42703: column "ARRAY[monday,friday]" does not exist
LINE 1: select 1 where 'monday' = ANY("ARRAY[monday,friday]");

I'm doing something wrong but I can't figure out what.

My real-world use case is that I have a psql script that will execute several queries on a long list of strings, and
ratherthan repeat those strings over and over in the script, I'd like to declare them once at the top of the script and
thenrefer to the variable after that. Bonus points if there's a way to do a multiline declaration like -- 

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

Thanks for reading
Philip


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: DBeaver does not show all tables in a Schema
Next
From: Oleg Serov
Date:
Subject: Question: Is it possible to get the new xlog position after query execution?