Can be SERVER_VERSION_NUM taken from connection info?


Here is a version with that, quite easy as well as the information was already there for other checks.

I have not updated "help.c" because the initial VERSION was not presented there in the first place.

--
Fabien.
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ad463e7..5046385 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 ("10") and number (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") 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.c
index 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.c
index 8068a28..91d6a8f 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -161,6 +161,11 @@ main(int argc, char *argv[])
 	EstablishVariableSpace();
 
 	SetVariable(pset.vars, "VERSION", PG_VERSION_STR);
+	SetVariable(pset.vars, "VERSION_NAME", PG_VERSION);
+
+#define STRINGIFY2(symbol) #symbol
+#define STRINGIFY(symbol) STRINGIFY2(symbol)
+	SetVariable(pset.vars, "VERSION_NUM", STRINGIFY(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:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to