Hello Pavel,

For this case can be nice to have function that returns server version as number some like version_num() .. 10000

The server side information can be queried:

  SELECT current_setting(‘server_version_num’)
    AS server_version_num \gset
  -- 90602

However client side is not so clean:

  \echo :VERSION
  PostgreSQL 10devel on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 
5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609, 64-bit

Probably some :VERSION_NUM would make some sense. See attached PoC patch.
Would it make sense?

diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index ad463e7..adc6a47 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3625,10 +3625,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 variable 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.
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[])
 	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:

Reply via email to