Re: psql \set variables in crosstab queries?

2023-03-04 Thread David G. Johnston
On Sat, Mar 4, 2023 at 10:05 PM Ron wrote: > > Ugh. It's a long and hairy query that would be a nightmare in a format > statement. > > Assuming you can pass this thing into the crosstab function in the first place you must already have put it into a string. Changing "crosstab" to "format", plop

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Ron
On 3/4/23 19:32, David G. Johnston wrote: On Sat, Mar 4, 2023 at 5:20 PM Ron wrote: But crosstab takes text strings as parameters.  How then do you use \set variables in crosstab queries? You need to dynamically write the textual query you want to send to the crosstab function.  In

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Ron
On 3/4/23 19:22, Tom Lane wrote: Ron writes: 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. Therefo

Re: psql \set variables in crosstab queries?

2023-03-04 Thread David G. Johnston
On Sat, Mar 4, 2023 at 5:20 PM Ron wrote: > > But crosstab takes text strings as parameters. How then do you use \set > variables in crosstab queries? > > You need to dynamically write the textual query you want to send to the crosstab function. In particular that means writing it using "format

Re: psql \set variables in crosstab queries?

2023-03-04 Thread Tom Lane
Ron writes: > 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 su

psql \set variables in crosstab queries?

2023-03-04 Thread Ron
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