Re: psql variables in the DO command

Поиск
Список
Период
Сортировка
От Pavel Stehule
Тема Re: psql variables in the DO command
Дата
Msg-id CAFj8pRB=Fb1gp+CorX82Qnz6aB34pkW3aOLCNFYNtcc-gAgM0Q@mail.gmail.com
обсуждение исходный текст
Ответ на Re: psql variables in the DO command  (Pavel Luzanov <p.luzanov@postgrespro.ru>)
Ответы Re: psql variables in the DO command
Список pgsql-general


2018-03-05 14:52 GMT+01:00 Pavel Luzanov <p.luzanov@postgrespro.ru>:
On 05.03.2018 16:42, Pavel Stehule wrote:

I can't use psql variable in the DO command. Is it intentional behavior?

yes. psql variables living on client side, and are not accessible from server side . DO command is executed on server side.

But SELECT command also executed on a server side ))
I thought that the command is sent to the server after variable's replacement.

The psql variables are injected into SQL string before execution (before SQL string is sent to server). But this injection is disabled inside strings - and body of DO command is passed as string.

postgres=# \set xxx ahoj
postgres=# select ':xxx';
+----------+
| ?column? |
+----------+
| :xxx     |
+----------+
(1 row)


Regards

Pavel
 


you can copy psql variables to GUC variables by set_config function, and then on server side use current_setting function for getting the content.
Yes, I know about workarounds.


-----
Pavel Luzanov
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company

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

Предыдущее
От: Pavel Luzanov
Дата:
Сообщение: Re: psql variables in the DO command
Следующее
От: Pavel Luzanov
Дата:
Сообщение: Re: psql variables in the DO command