From 32d37a74b323f05c7099509dd2dd702365433642 Mon Sep 17 00:00:00 2001 From: Carla Date: Fri, 2 Sep 2016 12:04:03 +0200 Subject: [PATCH] Remove cascades and quote conveniently --- src/pg/sql/50_table_level_framework.sql | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/pg/sql/50_table_level_framework.sql b/src/pg/sql/50_table_level_framework.sql index a42a827..5be85be 100644 --- a/src/pg/sql/50_table_level_framework.sql +++ b/src/pg/sql/50_table_level_framework.sql @@ -24,9 +24,12 @@ BEGIN EXCEPTION WHEN others THEN -- Disconnect user imported table. Delete schema and FDW server. - EXECUTE 'DROP FOREIGN TABLE IF EXISTS ' || fdw_import_schema || '.' || table_name; - EXECUTE 'DROP SCHEMA IF EXISTS ' || fdw_import_schema || ' CASCADE'; - EXECUTE 'DROP SERVER IF EXISTS ' || fdw_server || ' CASCADE;'; + EXECUTE 'DROP FOREIGN TABLE IF EXISTS "' || fdw_import_schema || '".' || table_name; + EXECUTE 'DROP FOREIGN TABLE IF EXISTS "' || fdw_import_schema || '".cdb_tablemetadata'; + EXECUTE 'DROP SCHEMA IF EXISTS "' || fdw_import_schema || '"'; + EXECUTE 'DROP USER MAPPING IF EXISTS FOR public SERVER "' || fdw_server || '"'; + EXECUTE 'DROP SERVER IF EXISTS "' || fdw_server || '"'; + RETURN (null, null, null); END; $$ LANGUAGE plpgsql SECURITY DEFINER; @@ -70,8 +73,10 @@ RETURNS boolean AS $$ BEGIN EXECUTE 'DROP FOREIGN TABLE IF EXISTS "' || table_schema || '".' || table_name; - EXECUTE 'DROP SCHEMA IF EXISTS ' || table_schema || ' CASCADE'; - EXECUTE 'DROP SERVER IF EXISTS ' || servername || ' CASCADE;'; + EXECUTE 'DROP FOREIGN TABLE IF EXISTS "' || table_schema || '".cdb_tablemetadata'; + EXECUTE 'DROP SCHEMA IF EXISTS "' || table_schema || '"'; + EXECUTE 'DROP USER MAPPING IF EXISTS FOR public SERVER "' || servername || '"'; + EXECUTE 'DROP SERVER IF EXISTS "' || servername || '"'; RETURN true; END; $$ LANGUAGE plpgsql SECURITY DEFINER;