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 1esrti-00071T-34 for pgsql-general@arkaria.postgresql.org; Mon, 05 Mar 2018 15:19:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1esrtg-0007sF-Kw for pgsql-general@arkaria.postgresql.org; Mon, 05 Mar 2018 15:19:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1esrtg-0007s5-6P for pgsql-general@lists.postgresql.org; Mon, 05 Mar 2018 15:19:28 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1esrtc-0003RB-3i for pgsql-general@lists.postgresql.org; Mon, 05 Mar 2018 15:19:26 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 25F5C21C1CA1; Mon, 5 Mar 2018 18:19:21 +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 C50D721C1C9F; Mon, 5 Mar 2018 18:19:20 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1520263160; bh=L7DLDShO/OfWKxz4wvpHUFCJ+66Z+FnN1c4+Z3jhzYY=; h=Subject:To:Cc:References:From:Date:In-Reply-To; b=aMUXjLCwkRZWN4UXdYlk3QIemDTRLas/c3C0udBNWfyu5jl0SHk5ZVm+AtmT0sgeu nLEpD3sB5ipTOkt7khO0/NvL9IqoJ3JwE3Z9zKkpPRTR9Tmmu2Z319nvcaCGshh0T/ vEwrfvKhgJH8wzRNP+K7WKRj0rR4BaPvf10DqxOg= 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: <36771268-3624-8f20-9e31-6598c15a1ee8@postgrespro.ru> Date: Mon, 5 Mar 2018 18:19:20 +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="------------9706F53B5ABA137EB6CFDEAB" 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. --------------9706F53B5ABA137EB6CFDEAB Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 05.03.2018 18:01, Pavel Stehule wrote: > > It is most correct when you thinking about it. > > 1. :xx is out of SQL syntax, so can by safely used. There is not risk > of unwanted usage. But there is absence of wanted usage too. > > 2. but string literal can contain :xxx symbols and not necessary it > means so it should be usage of psql variable - so additional syntax > for disabling evaluation should be necessary Yes and Oracle sqlplus (I khow than you know this tool) has special command to control this: set define ... > > Unfortunately DO command is half baked - and doesn't support > parameters. I am working on schema variables and I hope it will be a > solution of this issue: > > CREATE VARIABLE var as integer; > > LET var = :psqlintvar; > > DO $$ > BEGIN >   RAISE NOTICE '%', var; > END; > $$; > It will be great. I already commented it in your blog. ----- Pavel Luzanov Postgres Professional: http://www.postgrespro.com The Russian Postgres Company --------------9706F53B5ABA137EB6CFDEAB Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 05.03.2018 18:01, Pavel Stehule wrote:

It is most correct when you thinking about it.

1. :xx is out of SQL syntax, so can by safely used. There is not risk of unwanted usage.
But there is absence of wanted usage too.

2. but string literal can contain :xxx symbols and not necessary it means so it should be usage of psql variable - so additional syntax for disabling evaluation should be necessary
Yes and Oracle sqlplus (I khow than you know this tool) has special command to control this: set define ...


Unfortunately DO command is half baked - and doesn't support parameters. I am working on schema variables and I hope it will be a solution of this issue:

CREATE VARIABLE var as integer;

LET var = :psqlintvar;

DO $$
BEGIN
  RAISE NOTICE '%', var;
END;
$$;


It will be great. I already commented it in your blog.

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