From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: psql \set variables in crosstab queries?
Date: Sat, 4 Mar 2023 18:20:29 -0600
Message-ID: <1337b328-44f7-7f5b-cc1d-b8d11aced2cd@gmail.com> (raw)
According to
https://www.postgresql.org/docs/12/app-psql.html#APP-PSQL-VARIABLES and
experience, variables don't interpolate inside of string literals:
"
Variable interpolation will not be performed within quoted SQL literals and
identifiers. Therefore, a construction such as ':foo' doesn't work to
produce a quoted literal from a variable's value.
"
$ psql12 -v BOM=2023-02-01 -af foo.sql
select :'BOM'::timestamp + interval'6 month';
?column?
---------------------
2023-08-01 00:00:00
(1 row)
select $$ :BOM $$;
?column?
----------
:BOM
(1 row)
But crosstab takes text strings as parameters. How then do you use \set
variables in crosstab queries?
--
Born in Arizona, moved to Babylonia.
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: ronljohnsonjr@gmail.com
Subject: Re: psql \set variables in crosstab queries?
In-Reply-To: <1337b328-44f7-7f5b-cc1d-b8d11aced2cd@gmail.com>
References: <1337b328-44f7-7f5b-cc1d-b8d11aced2cd@gmail.com>
* 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