From d5f84784f07c14085d906459c4c8be366eb15cb8 Mon Sep 17 00:00:00 2001 From: Raul Marin Date: Wed, 30 Oct 2019 11:55:02 +0100 Subject: [PATCH] Add CDB_Federated_Table_Unregister --- .../CDB_FederatedServerTables.sql | 19 +++++++++++++++++++ test/CDB_FederatedServerTables.sql | 9 +++++++++ test/CDB_FederatedServerTables_expect | 2 ++ 3 files changed, 30 insertions(+) diff --git a/scripts-available/CDB_FederatedServerTables.sql b/scripts-available/CDB_FederatedServerTables.sql index 8f32b59..913fe32 100644 --- a/scripts-available/CDB_FederatedServerTables.sql +++ b/scripts-available/CDB_FederatedServerTables.sql @@ -171,3 +171,22 @@ BEGIN END $$ LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; + + +CREATE OR REPLACE FUNCTION @extschema@.CDB_Federated_Table_Unregister( + server TEXT, + remote_schema TEXT, + remote_table TEXT +) +RETURNS void +AS $$ +DECLARE + server_internal name := @extschema@.__CDB_FS_Generate_Server_Name(input_name := server, check_existence := false); + local_schema name := @extschema@.__CDB_FS_Create_Schema(server_internal, remote_schema); +BEGIN + EXECUTE FORMAT ('DROP FOREIGN TABLE %I.%I CASCADE;', local_schema, remote_table); + + +END +$$ +LANGUAGE PLPGSQL VOLATILE PARALLEL UNSAFE; diff --git a/test/CDB_FederatedServerTables.sql b/test/CDB_FederatedServerTables.sql index efd1074..42afbb0 100644 --- a/test/CDB_FederatedServerTables.sql +++ b/test/CDB_FederatedServerTables.sql @@ -78,6 +78,15 @@ SELECT 'R2', cartodb.CDB_Federated_Table_Register( SELECT 'V2', pg_get_viewdef('"myFullTable"'); SELECT 'S2', cartodb_id, ST_AsText(the_geom_webmercator), another_field FROM "myFullTable"; +SELECT 'U1', CDB_Federated_Table_Unregister( + server => 'loopback', + remote_schema => 'remote_schema', + remote_table => 'remote_geom' + ); +-- Selecting from the created view should fail now +SELECT 'UCheck1', cartodb_id, ST_AsText(the_geom), another_field FROM remote_geom; + + -- =================================================================== -- Cleanup diff --git a/test/CDB_FederatedServerTables_expect b/test/CDB_FederatedServerTables_expect index 78b44d1..a8fdf78 100644 --- a/test/CDB_FederatedServerTables_expect +++ b/test/CDB_FederatedServerTables_expect @@ -14,4 +14,6 @@ V2| SELECT t.id AS cartodb_id, t.another_field FROM cdb_fs_schema_b904664b5208433cd85a1693ba4f7570.remote_geom2 t; S2|3|POINT(3 3)|patata +U1| +ERROR: relation "remote_geom" does not exist at character 71 D1|