[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 3.0.4-4-g4cb6c8952

git at osgeo.org git at osgeo.org
Mon Jan 17 06:40:52 PST 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, stable-3.0 has been updated
       via  4cb6c89523885bc0eaa0ac94a8e96d8715c0f6a9 (commit)
      from  4e1e532fd15b1153937c787fa1dcec6913c2d9d2 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4cb6c89523885bc0eaa0ac94a8e96d8715c0f6a9
Author: Sandro Santilli <strk at kbt.io>
Date:   Thu Jan 13 23:57:36 2022 +0100

    Rewrite _postgis_drop_if_needed to avoid expanding DEFAULT values
    
    This prevents the function to fail when geometry canonical output
    function is non-functional (maybe due to lack of library on system).
    
    Closes #5046 in 3.0 branch (3.0.5dev)
    
    Includes NEWS item
    Include ugprades tests in absence of old library

diff --git a/NEWS b/NEWS
index f827b16ad..0cd4cd777 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,7 @@ PostGIS 3.0.5
 * Bug Fixes and Enhancements *
   - #5026, fix DropTopology in presence of UPDATE triggers on
            topology layers (Sandro Santilli)
+  - #5046, Fix upgrades in absence of old library (Sandro Santilli)
 
 PostGIS 3.0.4
 2021/09/04
diff --git a/postgis/postgis_before_upgrade.sql b/postgis/postgis_before_upgrade.sql
index 02ff21306..0e841e40e 100644
--- a/postgis/postgis_before_upgrade.sql
+++ b/postgis/postgis_before_upgrade.sql
@@ -37,34 +37,29 @@ CREATE OR REPLACE FUNCTION _postgis_drop_function_if_needed(
 	function_name text,
 	function_arguments text) RETURNS void AS $$
 DECLARE
-	frec RECORD;
 	sql_drop text;
+	postgis_namespace OID;
+	matching_function REGPROCEDURE;
 BEGIN
-	FOR frec IN
-		SELECT  p.oid as oid,
-				n.nspname as schema,
-				n.oid as schema_oid,
-				p.proname as name,
-				pg_catalog.pg_get_function_arguments(p.oid) as arguments,
-				pg_catalog.pg_get_function_identity_arguments(p.oid) as identity_arguments
-			FROM pg_catalog.pg_proc p
-			LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
-			WHERE
-				n.oid = (
-					SELECT n.oid
-					FROM pg_proc p
-					JOIN pg_namespace n ON p.pronamespace = n.oid
-					WHERE proname = 'postgis_full_version'
-					) AND
-				LOWER(p.proname) = LOWER(function_name) AND
-				LOWER(pg_catalog.pg_get_function_arguments(p.oid)) ~ LOWER(function_arguments) AND
-				pg_catalog.pg_function_is_visible(p.oid)
-			ORDER BY 1, 2, 4
-	LOOP
-		sql_drop := 'DROP FUNCTION ' || quote_ident(frec.schema) || '.' || quote_ident(frec.name) || ' ( ' || frec.identity_arguments || ' ) ';
-		RAISE DEBUG 'Name (%): %', frec.oid, frec.name;
-		RAISE DEBUG 'Arguments: %', frec.arguments;
-		RAISE DEBUG 'Identity arguments: %', frec.identity_arguments;
+
+	-- Fetch install namespace for PostGIS
+	SELECT n.oid
+	FROM pg_catalog.pg_proc p
+	JOIN pg_catalog.pg_namespace n ON p.pronamespace = n.oid
+	WHERE proname = 'postgis_full_version'
+	INTO postgis_namespace;
+
+	-- Find a function matching the given signature
+	SELECT oid
+	FROM pg_catalog.pg_proc p
+	WHERE pronamespace = postgis_namespace
+	AND LOWER(p.proname) = LOWER(function_name)
+	AND pg_catalog.pg_function_is_visible(p.oid)
+	AND LOWER(pg_catalog.pg_get_function_identity_arguments(p.oid)) ~ LOWER(function_arguments)
+	INTO matching_function;
+
+	IF matching_function IS NOT NULL THEN
+		sql_drop := 'DROP FUNCTION ' || matching_function;
 		RAISE DEBUG 'SQL query: %', sql_drop;
 		BEGIN
 			EXECUTE sql_drop;
@@ -72,7 +67,8 @@ BEGIN
 			WHEN OTHERS THEN
 				RAISE EXCEPTION 'Could not drop function %. You might need to drop dependant objects. Postgres error: %', function_name, SQLERRM;
 		END;
-	END LOOP;
+	END IF;
+
 END;
 $$ LANGUAGE plpgsql;
 
diff --git a/regress/run_test.pl b/regress/run_test.pl
index 8f32e5b79..bc2b1284e 100755
--- a/regress/run_test.pl
+++ b/regress/run_test.pl
@@ -350,6 +350,15 @@ sub create_upgrade_test_objects
       exit(1);
     }
   }
+
+  # Break current binary postgis functions
+  $query = "UPDATE pg_proc SET probin = probin || '-uninstalled' WHERE probin like '%postgis%'";
+  my $ret = sql($query);
+  unless ( $ret =~ /^UPDATE/ ) {
+    `dropdb $DB`;
+    print "\nSomething went wrong breaking postgis funx probin: $ret.\n";
+    exit(1);
+  }
 }
 
 sub drop_upgrade_test_objects

-----------------------------------------------------------------------

Summary of changes:
 NEWS                               |  1 +
 postgis/postgis_before_upgrade.sql | 50 ++++++++++++++++++--------------------
 regress/run_test.pl                |  9 +++++++
 3 files changed, 33 insertions(+), 27 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list