Hi I am sending a review of last patch psql-server-version-1.patch.gz
This patch is trivial - the most big problem is choosing correct name for GUC. I am thinking so server_version_raw is acceptable. I had to fix doc - see attached updated patch All tests passed. I'll mark this patch as ready for commiters Regards Pavel
diff --git a/doc/src/sgml/config.sgml b/doc/src/sgml/config.sgml index d360fc4d58..924766fce7 100644 --- a/doc/src/sgml/config.sgml +++ b/doc/src/sgml/config.sgml @@ -7956,8 +7956,22 @@ dynamic_library_path = 'C:\tools\postgresql;H:\my_project\lib;$libdir' </term> <listitem> <para> - Reports the version number of the server as an integer. It is determined - by the value of <literal>PG_VERSION_NUM</literal> when building the server. + Reports the version number of the server as a short string. It is determined + by the value of <literal>PG_VERSION</literal> when building the server. + </para> + </listitem> + </varlistentry> + + <varlistentry id="guc-server-raw" xreflabel="server_version_raw"> + <term><varname>server_version_raw</varname> (<type>string</type>) + <indexterm> + <primary><varname>server_version_raw</varname> configuration parameter</primary> + </indexterm> + </term> + <listitem> + <para> + Reports the version of the server as a long string. It is determined + by the value of <literal>PG_VERSION_STR</literal> when building the server. </para> </listitem> </varlistentry> diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml index e520cdf3ba..50d6f0a8fc 100644 --- a/doc/src/sgml/ref/psql-ref.sgml +++ b/doc/src/sgml/ref/psql-ref.sgml @@ -3770,11 +3770,14 @@ bar </varlistentry> <varlistentry> + <term><varname>SERVER_VERSION</varname></term> <term><varname>SERVER_VERSION_NAME</varname></term> <term><varname>SERVER_VERSION_NUM</varname></term> <listitem> <para> - The server's version number as a string, for + The server's version number as a long string, for + example <literal>PostgreSQL 11devel ...</literal>, + as a short string, for example <literal>9.6.2</literal>, <literal>10.1</literal> or <literal>11beta1</literal>, and in numeric form, for example <literal>90602</literal> or <literal>100001</literal>. diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index c4c1afa084..49ff61246f 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -500,6 +500,7 @@ static char *locale_collate; static char *locale_ctype; static char *server_encoding_string; static char *server_version_string; +static char *server_version_raw_string; static int server_version_num; static char *timezone_string; static char *log_timezone_string; @@ -3295,6 +3296,18 @@ static struct config_string ConfigureNamesString[] = NULL, NULL, NULL }, + { + /* Can't be set in postgresql.conf */ + {"server_version_raw", PGC_INTERNAL, PRESET_OPTIONS, + gettext_noop("Shows the server version string."), + NULL, + GUC_REPORT | GUC_NOT_IN_SAMPLE | GUC_DISALLOW_IN_FILE + }, + &server_version_raw_string, + PG_VERSION_STR, + NULL, NULL, NULL + }, + { /* Not for general use --- used by SET ROLE */ {"role", PGC_USERSET, UNGROUPED, diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 8cc4de3878..cfac89c8da 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3210,7 +3210,8 @@ void SyncVariables(void) { char vbuf[32]; - const char *server_version; + const char *server_version, + *server_version_raw; /* get stuff from connection */ pset.encoding = PQclientEncoding(pset.db); @@ -3237,6 +3238,17 @@ SyncVariables(void) snprintf(vbuf, sizeof(vbuf), "%d", pset.sversion); SetVariable(pset.vars, "SERVER_VERSION_NUM", vbuf); + server_version_raw = PQparameterStatus(pset.db, "server_version_raw"); + /* fall back again */ + if (!server_version_raw) + { + snprintf(vbuf, sizeof(vbuf), "PostgreSQL "); + formatPGVersionNumber(pset.sversion, true, vbuf + strlen(vbuf), + sizeof(vbuf) - strlen(vbuf)); + server_version_raw = vbuf; + } + SetVariable(pset.vars, "SERVER_VERSION", server_version_raw); + /* send stuff to it, too */ PQsetErrorVerbosity(pset.db, pset.verbosity); PQsetErrorContextVisibility(pset.db, pset.show_context); @@ -3255,6 +3267,7 @@ UnsyncVariables(void) SetVariable(pset.vars, "HOST", NULL); SetVariable(pset.vars, "PORT", NULL); SetVariable(pset.vars, "ENCODING", NULL); + SetVariable(pset.vars, "SERVER_VERSION", NULL); SetVariable(pset.vars, "SERVER_VERSION_NAME", NULL); SetVariable(pset.vars, "SERVER_VERSION_NUM", NULL); } diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c index 5335a91440..0418779f79 100644 --- a/src/interfaces/libpq/fe-protocol2.c +++ b/src/interfaces/libpq/fe-protocol2.c @@ -280,6 +280,10 @@ pqSetenvPoll(PGconn *conn) { char *ptr; + /* keep returned value */ + pqSaveParameterStatus(conn, "server_version_raw", + val); + /* strip off PostgreSQL part */ val += 11; diff --git a/src/test/regress/expected/guc.out b/src/test/regress/expected/guc.out index 43ac5f5f11..eabb990d4e 100644 --- a/src/test/regress/expected/guc.out +++ b/src/test/regress/expected/guc.out @@ -767,3 +767,14 @@ NOTICE: text search configuration "no_such_config" does not exist select func_with_bad_set(); ERROR: invalid value for parameter "default_text_search_config": "no_such_config" reset check_function_bodies; +-- check consistency of SERVER_VERSION +-- which is transmitted as GUC "server_version_raw" +SELECT :'SERVER_VERSION' = VERSION() + AND :'SERVER_VERSION' = current_setting('server_version_raw') + AND :'SERVER_VERSION' = :'VERSION' + AS "SERVER_VERSION is consistent"; + SERVER_VERSION is consistent +------------------------------ + t +(1 row) + diff --git a/src/test/regress/sql/guc.sql b/src/test/regress/sql/guc.sql index 23e5029780..af2e353da0 100644 --- a/src/test/regress/sql/guc.sql +++ b/src/test/regress/sql/guc.sql @@ -288,3 +288,10 @@ set default_text_search_config = no_such_config; select func_with_bad_set(); reset check_function_bodies; + +-- check consistency of SERVER_VERSION +-- which is transmitted as GUC "server_version_raw" +SELECT :'SERVER_VERSION' = VERSION() + AND :'SERVER_VERSION' = current_setting('server_version_raw') + AND :'SERVER_VERSION' = :'VERSION' + AS "SERVER_VERSION is consistent";
-- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers