Re: psql \set variables in crosstab queries?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: psql \set variables in crosstab queries?
Дата
Msg-id 3054299.1677979338@sss.pgh.pa.us
обсуждение исходный текст
Ответ на psql \set variables in crosstab queries?  (Ron <ronljohnsonjr@gmail.com>)
Ответы Re: psql \set variables in crosstab queries?  (Ron <ronljohnsonjr@gmail.com>)
Список pgsql-general
Ron <ronljohnsonjr@gmail.com> 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 such as ':foo' doesn't work to 
> produce a quoted literal from a variable's value.
> "

> But crosstab takes text strings as parameters.  How then do you use \set 
> variables in crosstab queries?

If you read a little further, you'll find out the syntax for converting
the value of a psql variable to a SQL string literal:

regression=# \set foo BAR
regression=# select ':foo';
 ?column? 
----------
 :foo
(1 row)

regression=# select :'foo';
 ?column? 
----------
 BAR
(1 row)

What the server got in the last case was "select 'BAR';".

            regards, tom lane



В списке pgsql-general по дате отправления:

Предыдущее
От: Ron
Дата:
Сообщение: psql \set variables in crosstab queries?
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: psql \set variables in crosstab queries?