forked from postgis/postgis
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). References #5046 in master branch Includes regression testing, which now avoid keeping geometry_out functional.master
parent
bf01900ee9
commit
95bedd94bb
|
@ -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;
|
||||
|
||||
|
|
|
@ -77,10 +77,5 @@ FROM upgrade_test;
|
|||
|
||||
-- Break probin of all postgis functions, as we expect
|
||||
-- the upgrade procedure to replace them all
|
||||
UPDATE pg_proc SET probin = probin || '-uninstalled' WHERE probin like '%postgis%'
|
||||
-- Some function have DEFAULT values for GEOMETRY type, which
|
||||
-- makes pg_get_function_arguments choke. This should be fixed!
|
||||
-- See https://trac.osgeo.org/postgis/ticket/5046#comment:5
|
||||
-- When ticket #5046 is fixed we can ALSO break geometry_out
|
||||
AND proname NOT IN ( 'geometry_out')
|
||||
;
|
||||
UPDATE pg_proc SET probin = probin || '-uninstalled'
|
||||
WHERE probin like '%postgis%';
|
||||
|
|
Loading…
Reference in New Issue