psql \set variables in crosstab queries?

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: psql \set variables in crosstab queries?
Date: 2023-03-05 00:20:29
Message-ID: 1337b328-44f7-7f5b-cc1d-b8d11aced2cd@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2023-03-05 01:22:18 Re: psql \set variables in crosstab queries?
Previous Message Ron 2023-03-04 22:01:44 Re: Dropping behavior for unique CONSTRAINTs