From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Allow psql variable substitution to occur in backtick command st
Date: Sun, 02 Apr 2017 01:45:05 +0000
Message-ID: <E1cuUZl-0004WO-4J@gemulon.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-committers>
Allow psql variable substitution to occur in backtick command strings.
Previously, text between backquotes in a psql metacommand's arguments
was always passed to the shell literally. That considerably hobbles
the usefulness of the feature for scripting, so we'd foreseen for a long
time that we'd someday want to allow substitution of psql variables into
the shell command. IMO the addition of \if metacommands has brought us to
that point, since \if can greatly benefit from some sort of client-side
expression evaluation capability, and psql itself is not going to grow any
such thing in time for v10. Hence, this patch. It allows :VARIABLE to be
replaced by the exact contents of the named variable, while :'VARIABLE'
is replaced by the variable's contents suitably quoted to become a single
shell-command argument. (The quoting rules for that are different from
those for SQL literals, so this is a bit of an abuse of the :'VARIABLE'
notation, but I doubt anyone will be confused.)
As with other situations in psql, no substitution occurs if the word
following a colon is not a known variable name. That limits the risk of
compatibility problems for existing psql scripts; but the risk isn't zero,
so this needs to be called out in the v10 release notes.
Discussion: https://postgr.es/m/9561.1490895211@sss.pgh.pa.us
Branch
------
master
Details
-------
http://git.postgresql.org/pg/commitdiff/f833c847b8fa4782efab45c8371d3cee64292d9b
Modified Files
--------------
doc/src/sgml/ref/psql-ref.sgml | 29 ++++++++---
src/bin/psql/common.c | 98 +++++++++++++++++++++++++------------
src/bin/psql/common.h | 3 +-
src/bin/psql/psqlscanslash.l | 52 +++++++++++++++++---
src/fe_utils/psqlscan.l | 13 ++---
src/fe_utils/string_utils.c | 33 +++++++++----
src/include/fe_utils/psqlscan.h | 15 ++++--
src/include/fe_utils/psqlscan_int.h | 2 +-
src/include/fe_utils/string_utils.h | 1 +
9 files changed, 180 insertions(+), 66 deletions(-)
--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Allow psql variable substitution to occur in backtick command st
In-Reply-To: <E1cuUZl-0004WO-4J@gemulon.postgresql.org>
References: <E1cuUZl-0004WO-4J@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox