psql \set variables in crosstab queries? - Mailing list pgsql-general

From Ron
Subject psql \set variables in crosstab queries?
Date
Msg-id 1337b328-44f7-7f5b-cc1d-b8d11aced2cd@gmail.com
Whole thread Raw
Responses Re: psql \set variables in crosstab queries?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: psql \set variables in crosstab queries?  ("David G. Johnston" <david.g.johnston@gmail.com>)
List 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.



pgsql-general by date:

Previous
From: Ron
Date:
Subject: Re: Dropping behavior for unique CONSTRAINTs
Next
From: Tom Lane
Date:
Subject: Re: psql \set variables in crosstab queries?