Re: psql variables in the DO command - Mailing list pgsql-general

From Pavel Luzanov
Subject Re: psql variables in the DO command
Date
Msg-id e40d6745-1b47-0fbe-b344-185ea317fd60@postgrespro.ru
Whole thread Raw
In response to Re: psql variables in the DO command  (Pavel Stehule <pavel.stehule@gmail.com>)
Responses Re: psql variables in the DO command  (Pavel Luzanov <p.luzanov@postgrespro.ru>)
Re: psql variables in the DO command  (Pavel Stehule <pavel.stehule@gmail.com>)
List pgsql-general
On 05.03.2018 16:56, 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.
Yes, now I understand this. But at first glance this is not an obvious behavior.

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

pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: psql variables in the DO command
Next
From: Łukasz Jarych
Date:
Subject: Re: Requiring pass and database psql shell command