[postgis-tickets] r15602 - Add check for PostgreSQL version compatibility in postgis_full_version

Sandro Santilli strk at kbt.io
Mon Aug 28 13:29:14 PDT 2017


Author: strk
Date: 2017-08-28 13:29:14 -0700 (Mon, 28 Aug 2017)
New Revision: 15602

Modified:
   trunk/postgis/postgis.sql.in
   trunk/postgis/sqldefines.h.in
Log:
Add check for PostgreSQL version compatibility in postgis_full_version

Adds postgis_scripts_pgsql_version() and postgis_pgsql_version()
internal functions, each returning an encoded version number,
and has postgis_full_version() compare running vs. build-time used

Fixes #3822 (untested)

Modified: trunk/postgis/postgis.sql.in
===================================================================
--- trunk/postgis/postgis.sql.in	2017-08-28 15:20:06 UTC (rev 15601)
+++ trunk/postgis/postgis.sql.in	2017-08-28 20:29:14 UTC (rev 15602)
@@ -2772,6 +2772,15 @@
 	AS 'MODULE_PATHNAME'
 	LANGUAGE 'c' IMMUTABLE;
 
+CREATE OR REPLACE FUNCTION postgis_scripts_pgsql_version() RETURNS text
+	AS _POSTGIS_SQL_SELECT_POSTGIS_PGSQL_VERSION
+	LANGUAGE 'sql' IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION postgis_pgsql_version() RETURNS text
+AS $$
+	select regexp_replace(version(), 'PostgreSQL ([^.]*)\.([^\.]*).* on .*', E'\\1\\2');
+$$ LANGUAGE 'sql' STABLE;
+
 CREATE OR REPLACE FUNCTION postgis_full_version() RETURNS text
 AS $$
 DECLARE
@@ -2794,12 +2803,16 @@
 	protobuf_lib_ver text;
 	sfcgal_lib_ver text;
 	sfcgal_scr_ver text;
+	pgsql_scr_ver text;
+	pgsql_ver text;
 BEGIN
 	SELECT @extschema at .postgis_lib_version() INTO libver;
 	SELECT @extschema at .postgis_proj_version() INTO projver;
 	SELECT @extschema at .postgis_geos_version() INTO geosver;
 	SELECT @extschema at .postgis_libjson_version() INTO json_lib_ver;
 	SELECT @extschema at .postgis_libprotobuf_version() INTO protobuf_lib_ver;
+	SELECT @extschema at .postgis_scripts_pgsql_version() INTO pgsql_scr_ver;
+	SELECT @extschema at .postgis_pgsql_version() INTO pgsql_ver;
 	BEGIN
 		SELECT @extschema at .postgis_gdal_version() INTO gdalver;
 	EXCEPTION
@@ -2900,6 +2913,10 @@
 		fullver = fullver || ' (core procs from "' || dbproc || '" need upgrade)';
 	END IF;
 
+	IF pgsql_scr_ver != pgsql_ver THEN
+		fullver = fullver || ' (procs built against PostgreSQL "' || pgsql_scr_ver || '" need upgrade)';
+	END IF;
+
 	IF topo_scr_ver IS NOT NULL THEN
 		fullver = fullver || ' TOPOLOGY';
 		IF topo_scr_ver != relproc THEN

Modified: trunk/postgis/sqldefines.h.in
===================================================================
--- trunk/postgis/sqldefines.h.in	2017-08-28 15:20:06 UTC (rev 15601)
+++ trunk/postgis/sqldefines.h.in	2017-08-28 20:29:14 UTC (rev 15602)
@@ -26,6 +26,7 @@
  */
 #define _POSTGIS_SQL_SELECT_POSTGIS_VERSION 'SELECT ''@POSTGIS_VERSION@''::text AS version'
 #define _POSTGIS_SQL_SELECT_POSTGIS_BUILD_DATE 'SELECT ''@POSTGIS_BUILD_DATE@''::text AS version'
+#define _POSTGIS_SQL_SELECT_POSTGIS_PGSQL_VERSION 'SELECT ''@POSTGIS_PGSQL_VERSION@''::text AS version'
 
 #if POSTGIS_SVN_REVISION
 #define _POSTGIS_SQL_SELECT_POSTGIS_SCRIPTS_VERSION $$ SELECT '@POSTGIS_SCRIPTS_VERSION@'::text || ' r' || POSTGIS_SVN_REVISION::text AS version $$



More information about the postgis-tickets mailing list