Hello Tom,

I understand that you would prefer VERSION_NAME to show something like
   "11devel, server 9.6.4"

No, that's not what I said.  I'm just complaining that as the patch stands
it will set SERVER_NAME to "11.0", where I think it should say "11devel"
(as of today).


  VERSION "PostgreSQL 11devel on ..."

This kind of inconsistencies is hard for human memory:-(

or just leaving "CLIENT" implicit for all of these variables:

  VERSION "PostgreSQL 11devel on ..."
  VERSION_NAME "11devel"
  VERSION_NUM 110000

That is already what the patch does, because of the VERSION precedent.

Robert seems to prefer the last of those, and that'd be fine with me.
(Note that CLIENT is ambiguous anyway: does it mean psql itself, or

Hmmm. Indeed.


I'm on board with this, except I don't think we should have any leading
zero in the numeric form.  There are contexts where somebody might think
that means octal.

Indeed. The implementation already does this, I just typed it without checking.

So basically the only thing needed from Robert & you seems to change "11.0" to "11devel", which is fine with me.

The attached v5 does that.

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index c592eda..c611f39 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3688,6 +3688,18 @@ bar
+        <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>
@@ -3733,10 +3745,13 @@ bar
+        <term><varname>VERSION_NAME</varname></term>
+        <term><varname>VERSION_NUM</varname></term>
-        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.
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 96f3a40..3c1924e 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3337,6 +3337,8 @@ checkWin32Codepage(void)
+	char vbuf[32];
 	/* get stuff from connection */
 	pset.encoding = PQclientEncoding(pset.db);
 	pset.popt.topt.encoding = pset.encoding;
@@ -3348,6 +3350,11 @@ 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", PQparameterStatus(pset.db, "server_version"));
+	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);
@@ -3366,6 +3373,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.c
index 7f76797..4065539 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -161,6 +161,8 @@ main(int argc, char *argv[])
 	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");
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to