Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1esqYw-0000MW-23 for pgsql-general@arkaria.postgresql.org; Mon, 05 Mar 2018 13:53:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1esqYu-0001Ie-R0 for pgsql-general@arkaria.postgresql.org; Mon, 05 Mar 2018 13:53:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1esqXg-00048C-Ox for pgsql-general@lists.postgresql.org; Mon, 05 Mar 2018 13:52:40 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1esqXc-00024A-F5 for pgsql-general@lists.postgresql.org; Mon, 05 Mar 2018 13:52:39 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 2E98421C1C7F; Mon, 5 Mar 2018 16:52:35 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=x tagged_above=-99 required=4 WHITELISTED tests=[] autolearn=unavailable Received: from [192.168.27.41] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 5EA0D21C1C73; Mon, 5 Mar 2018 16:52:33 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1520257955; bh=tC5537Ckinv/lN2r3e1trYrlMHx2t/HT8qQGDl1H9w4=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=CRsHSeq5lhWmX/DiBUfebQ6DAS9TV5JWtAESPL8euvRLk/6ZD9M5gERAY0UI2BqST BJAyzmzvRacJ26T5/hGuEIWaFpPruD3uGd9eqg+aTLdhNUIzs0aIAiEj8zDq9+zI1o e5zl8YG9AVA8raQBR6TWkzRR3CzLgUav1IImKzC8= Subject: Re: psql variables in the DO command To: Pavel Stehule Cc: pgsql-general References: <5bae153c-ade4-ad24-bd46-857993240cfd@postgrespro.ru> From: Pavel Luzanov Message-ID: Date: Mon, 5 Mar 2018 16:52:32 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------BAC5ACA68595CC31CC65CA9C" Content-Language: ru-RU List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------BAC5ACA68595CC31CC65CA9C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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. > > 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 --------------BAC5ACA68595CC31CC65CA9C Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit 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.


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
--------------BAC5ACA68595CC31CC65CA9C--