Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ctdya-0005ef-Id for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Mar 2017 17:35:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1ctdyZ-0002YT-Ti for pgsql-hackers@arkaria.postgresql.org; Thu, 30 Mar 2017 17:35:11 +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 1ctdx4-0008In-Sd for pgsql-hackers@postgreSQL.org; Thu, 30 Mar 2017 17:33:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ctdwy-0001UR-7S for pgsql-hackers@postgreSQL.org; Thu, 30 Mar 2017 17:33:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v2UHXVu4009562 for ; Thu, 30 Mar 2017 13:33:31 -0400 From: Tom Lane To: pgsql-hackers@postgreSQL.org Subject: Variable substitution in psql backtick expansion MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9560.1490895211.1@sss.pgh.pa.us> Date: Thu, 30 Mar 2017 13:33:31 -0400 Message-ID: <9561.1490895211@sss.pgh.pa.us> 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 Awhile back in the discussion about the \if feature for psql, I'd pointed out that you shouldn't really need very much in the way of boolean-expression evaluation smarts, because you ought to be able to use a backtick shell escape: \if `expr :foo \> :bar` \echo :foo is greater than :bar \endif Now that the basic feature is in, I went to play around with this, and was disappointed to find out that it doesn't work. The reason is not far to seek: we do not do variable substitution within the text between backticks. psqlscanslash.l already foresaw that some day we'd want to do that: /* * backticked text: copy everything until next backquote, then evaluate. * * XXX Possible future behavioral change: substitute for :VARIABLE? */ I think today is that day, because it's going to make a material difference to the usability of this feature. I propose extending backtick processing so that 1. :VARIABLE is replaced by the contents of the variable 2. :'VARIABLE' is replaced by the contents of the variable, single-quoted according to Unix shell conventions. (So the processing would be a bit different from what it is for the same notation in SQL contexts.) This doesn't look like it would take very much new code to do. Thoughts? regards, tom lane -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers