Add CDB_Federated_Table_Unregister

This commit is contained in:
Raul Marin 2019-10-30 11:55:02 +01:00
parent 7bb0b93f8b
commit d5f84784f0
3 changed files with 30 additions and 0 deletions

View File

@ -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;

View File

@ -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

View File

@ -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|