From: Fabien COELHO <coelho@cri.ensmp.fr>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Corey Huinker <corey.huinker@gmail.com>
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: Daniel Verite <daniel@manitou-mail.org>
Cc: PostgreSQL Developers <pgsql-hackers@postgresql.org>
Subject: Re: Variable substitution in psql backtick expansion
Date: Sun, 2 Apr 2017 21:57:41 +0200 (CEST)
Message-ID: <alpine.DEB.2.20.1704022151080.9265@lancre> (raw)
In-Reply-To: <3926.1491159242@sss.pgh.pa.us>
References: <bc15034d-b421-42ac-89b1-c3485fa1728b@manitou-mail.org>
<alpine.DEB.2.20.1704020841490.4632@lancre>
<CAFj8pRDCfLLNfMyNAjDwgHXS7inThdqgCaSbfKpiYXkb6Mvmwg@mail.gmail.com>
<alpine.DEB.2.20.1704020917220.4632@lancre>
<CAFj8pRCVFp+68Tt29sZfn9tE28c2D7u_VzTcXrqjyCVBzAzRsA@mail.gmail.com>
<alpine.DEB.2.20.1704021303300.4632@lancre>
<CAFj8pRACH1M=egydH4dAAoo9rRVTkuYCaoyZQK2Yf4BTQuRM5w@mail.gmail.com>
<CADkLM=dzsbgJdP7KAJnbihxU1XFnWZgit9ye5cWnvkjZXyPbGw@mail.gmail.com>
<alpine.DEB.2.20.1704021805550.4632@lancre>
<CADkLM=c+hm2rc0tkKgC-ZgrLttHT2KkfppE+BC-=i-xj+7V-TQ@mail.gmail.com>
<3926.1491159242@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
> More to the point, we already have that. See c.h:
>
> #define CppAsString(identifier) #identifier
> #define CppAsString2(x) CppAsString(x)
Thanks for the pointer. I grepped for them without success. Here is a v4.
--
Fabien
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:psql-version-num-4.patch (text/x-diff, 3.2K) downloaddiff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgmlindex ad463e7..b1508be 100644--- a/doc/src/sgml/ref/psql-ref.sgml+++ b/doc/src/sgml/ref/psql-ref.sgml@@ -3580,6 +3580,18 @@ bar
</varlistentry>
<varlistentry>
+ <term><varname>SERVER_VERSION_NAME</varname></term>+ <term><varname>SERVER_VERSION_NUM</varname></term>+ <listitem>+ <para>+ These variables are set when connected to reflects the server's version+ both in short name (eg "9.6.2", "10.0") and number (eg 90602, 100000).+ They can be changed or unset.+ </para>+ </listitem>+ </varlistentry>++ <varlistentry>
<term><varname>SINGLELINE</varname></term>
<listitem>
<para>
@@ -3625,10 +3637,13 @@ bar
<varlistentry>
<term><varname>VERSION</varname></term>
+ <term><varname>VERSION_NAME</varname></term>+ <term><varname>VERSION_NUM</varname></term>
<listitem>
<para>
- This variable is set at program start-up to- reflect <application>psql</>'s version. It can be changed or unset.+ These variables are set at program start-up to reflect+ <application>psql</>'s version in verbose, short name ("10.0")+ and number (100000). They can be changed or unset.
</para>
</listitem>
</varlistentry>
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.cindex 94a3cfc..2c58cfb 100644--- a/src/bin/psql/command.c+++ b/src/bin/psql/command.c@@ -3320,6 +3320,8 @@ checkWin32Codepage(void)
void
SyncVariables(void)
{
+ char vbuf[32];+
/* get stuff from connection */
pset.encoding = PQclientEncoding(pset.db);
pset.popt.topt.encoding = pset.encoding;
@@ -3331,6 +3333,12 @@ SyncVariables(void)
SetVariable(pset.vars, "PORT", PQport(pset.db));
SetVariable(pset.vars, "ENCODING", pg_encoding_to_char(pset.encoding));
+ /* server version information */+ SetVariable(pset.vars, "SERVER_VERSION_NAME",+ formatPGVersionNumber(pset.sversion, true, vbuf, sizeof(vbuf)));+ snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion);+ SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf);+
/* send stuff to it, too */
PQsetErrorVerbosity(pset.db, pset.verbosity);
PQsetErrorContextVisibility(pset.db, pset.show_context);
@@ -3349,6 +3357,8 @@ UnsyncVariables(void)
SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL);
SetVariable(pset.vars, "ENCODING", NULL);
+ SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL);+ SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL);
}
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.cindex 8068a28..68b6724 100644--- a/src/bin/psql/startup.c+++ b/src/bin/psql/startup.c@@ -161,6 +161,8 @@ main(int argc, char *argv[])
EstablishVariableSpace();
SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
+ SetVariable(pset.vars, "VERSION_NAME", PG_VERSION);+ SetVariable(pset.vars, "VERSION_NUM", CppAsString2(PG_VERSION_NUM));
/* Default values for variables (that don't match the result of \unset) */
SetVariableBool(pset.vars, "AUTOCOMMIT");
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 using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: coelho@cri.ensmp.fr, tgl@sss.pgh.pa.us, corey.huinker@gmail.com, pavel.stehule@gmail.com, daniel@manitou-mail.org
Subject: Re: Variable substitution in psql backtick expansion
In-Reply-To: <alpine.DEB.2.20.1704022151080.9265@lancre>
* 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