Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvJIv-000227-RM for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Apr 2017 07:55:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cvJIu-0006lt-6J for pgsql-hackers@arkaria.postgresql.org; Tue, 04 Apr 2017 07:55:04 +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.84_2) (envelope-from ) id 1cvJHO-00045S-HW for pgsql-hackers@postgresql.org; Tue, 04 Apr 2017 07:53:30 +0000 Received: from boipeva.ensmp.fr ([194.214.158.136] helo=cc-tupan-roaming-b.ensmp.fr) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvJHF-0002uI-Qu for pgsql-hackers@postgresql.org; Tue, 04 Apr 2017 07:53:28 +0000 Received: from cri.ensmp.fr (pau-rnt.cri.ensmp.fr [195.83.117.250]) (authenticated bits=0) by cc-tupan-roaming-b.ensmp.fr (8.15.2/8.15.2/JMMC-22/Oct/2013) with ESMTPSA id v347rD5H026279 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 4 Apr 2017 09:53:17 +0200 Date: Tue, 4 Apr 2017 09:53:13 +0200 (CEST) From: Fabien COELHO X-X-Sender: coelho@hendaye To: Pavel Stehule cc: Tom Lane , Daniel Verite , PostgreSQL Developers Subject: Re: Variable substitution in psql backtick expansion In-Reply-To: Message-ID: References: <12587.1491228978@sss.pgh.pa.us> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Miltered: at cc-tupan-roaming-b.ensmp.fr with ID 58E350E9.002 by Joe's j-chkmail (http : // j-chkmail dot ensmp dot fr)! X-j-chkmail-Auth: USER-ID fabien.coelho X-j-chkmail-Enveloppe: 58E350E9.002 from pau-rnt.cri.ensmp.fr/pau-rnt.cri.ensmp.fr/195.83.117.250/cri.ensmp.fr/ X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org Hello Pavel, > The expression evaluation is interesting question, but there is a > workaround - we can use \gset already. Yes, that is a good point. It is a little bit inconvenient because it requires a dummy variable name each time for testing. SELECT whatever AS somename \gset \if :somename But this is an already functional solution to use server-side expressions, so there is no hurry. > What is more important, because there is not any workaround, is detection > if some variable exists or not. > > So possibilities > > 1. \if defined varname Yep, and as Tom pointed it should handle NOT as well. My issue with this version is that Lane Tom convinced me some time ago that client side expressions should look like SQL expressions, so that everything in the script is somehow in the same language. I think that he made a good point. However "defined varname" is definitely not an SQL expression, so I do not find that "intuitive", for a given subjective idea of intuitive. Then there is the question of simple comparisons, which would also make sense client-side, eg simple things like: \if :VERSION_NUM >= 110000 Should not need to be executed on the server. > 2. \ifdefined or \ifdef varname I think that we want to avoid that if possible, but it is a cpp-like possibility. This approach does not allow to support comparisons. > 3. \if :?varname Tom suggested that there is a special namespace problem with this option. I did not understand what is the actual issue. > I like first two, and I can live with @3 - although it is not intuitive For me @3 is neither worth nor better than the already existing :'varname' and :"varname" hacks, it is consistent with them, so it is just an extension of the existing approach. It seems easy to implement because the substitution would be handled by the lexer, so there is no need for anything special like looking at the first or second word, rewinding, whatever. Basically I agree with everything Tom suggested (indeed, some client side definition & comparison tests are really needed), but not with the proposed prefix syntax because it does not look clean and SQL. -- Fabien. -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers