[postgis-tickets] r17341 - Refuse to load PostGIS in an untargeted PostgreSQL version

Raúl Marín Rodríguez rmrodriguez at carto.com
Wed Mar 13 08:17:40 PDT 2019


This is going to break https://trac.osgeo.org/postgis/ticket/4296.

Can you use server_version_num instead of the regex?


On Wed, Mar 13, 2019 at 4:10 PM Sandro Santilli <strk at kbt.io> wrote:
>
> Author: strk
> Date: 2019-03-13 08:10:40 -0700 (Wed, 13 Mar 2019)
> New Revision: 17341
>
> Modified:
>    trunk/configure.ac
>    trunk/postgis/postgis.sql.in
>    trunk/postgis/sqldefines.h.in
> Log:
> Refuse to load PostGIS in an untargeted PostgreSQL version
>
> Helps user finding out what problems they have when this happens
>
> Modified: trunk/configure.ac
> ===================================================================
> --- trunk/configure.ac  2019-03-13 15:10:30 UTC (rev 17340)
> +++ trunk/configure.ac  2019-03-13 15:10:40 UTC (rev 17341)
> @@ -466,6 +466,7 @@
>    fi
>
>    POSTGIS_PGSQL_VERSION="$PGSQL_MAJOR_VERSION$PGSQL_MINOR_VERSION"
> +  POSTGIS_PGSQL_HR_VERSION="$PGSQL_MAJOR_VERSION.$PGSQL_MINOR_VERSION"
>
>    PGSQL_PKGLIBDIR=`"$PG_CONFIG" --pkglibdir`
>    PGSQL_LIBDIR=`"$PG_CONFIG" --libdir`
> @@ -550,6 +551,8 @@
>
>    AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_VERSION], [$POSTGIS_PGSQL_VERSION], [PostgreSQL server version])
>    AC_SUBST([POSTGIS_PGSQL_VERSION])
> +  AC_DEFINE_UNQUOTED([POSTGIS_PGSQL_HR_VERSION], [$POSTGIS_PGSQL_HR_VERSION], [PostgreSQL human readable server version])
> +  AC_SUBST([POSTGIS_PGSQL_HR_VERSION])
>    AC_SUBST([HAVE_SPGIST])
>
>  fi dnl LIBLWGEOM_ONLY != no
>
> Modified: trunk/postgis/postgis.sql.in
> ===================================================================
> --- trunk/postgis/postgis.sql.in        2019-03-13 15:10:30 UTC (rev 17340)
> +++ trunk/postgis/postgis.sql.in        2019-03-13 15:10:40 UTC (rev 17341)
> @@ -25,6 +25,27 @@
>  BEGIN;
>  SET LOCAL client_min_messages TO warning;
>
> +DO $$
> +DECLARE
> +       pgver text;
> +BEGIN
> +       SELECT substring(version(), 'PostgreSQL ([0-9\.]+)') INTO pgver;
> +
> +       IF POSTGIS_PGSQL_VERSION::text != ( SELECT CASE
> +               WHEN split_part(s,'.',1)::integer > 9
> +                       THEN split_part(s,'.',1) || '0'
> +               ELSE
> +                       split_part(s,'.', 1) || split_part(s,'.', 2)
> +               END
> +               FROM substring(version(), 'PostgreSQL ([0-9\.]+)') AS s )
> +       THEN
> +               RAISE EXCEPTION 'PostGIS built for PostgreSQL % cannot be loaded in PostgreSQL %',
> +                       POSTGIS_PGSQL_HR_VERSION, pgver;
> +       END IF;
> +END;
> +$$;
> +
> +
>  -- Check that no other postgis is installed
>  DO $$
>  DECLARE
> @@ -2952,7 +2973,7 @@
>
>         fullver = fullver || ' PGSQL="' || pgsql_scr_ver || '"';
>         IF pgsql_scr_ver != pgsql_ver THEN
> -               fullver = fullver || ' (procs need upgrade for use with "' || pgsql_ver || '")';
> +               fullver = fullver || ' (procs need upgrade for use with PostgreSQL "' || pgsql_ver || '")';
>         END IF;
>
>         IF  geosver IS NOT NULL THEN
>
> Modified: trunk/postgis/sqldefines.h.in
> ===================================================================
> --- trunk/postgis/sqldefines.h.in       2019-03-13 15:10:30 UTC (rev 17340)
> +++ trunk/postgis/sqldefines.h.in       2019-03-13 15:10:40 UTC (rev 17341)
> @@ -7,6 +7,7 @@
>   * Define just the version numbers; otherwise we get some strange substitutions in postgis.sql.in
>   */
>  #define POSTGIS_PGSQL_VERSION @POSTGIS_PGSQL_VERSION@
> +#define POSTGIS_PGSQL_HR_VERSION @POSTGIS_PGSQL_HR_VERSION@
>  #define POSTGIS_GEOS_VERSION @POSTGIS_GEOS_VERSION@
>  #define POSTGIS_PROJ_VERSION @POSTGIS_PROJ_VERSION@
>  #define POSTGIS_LIB_VERSION '@POSTGIS_LIB_VERSION@'
>
> _______________________________________________
> postgis-tickets mailing list
> postgis-tickets at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-tickets



--
Raúl Marín Rodríguez
carto.com


More information about the postgis-tickets mailing list