CDB_Federated_Table_Register: Handle conflict nicely

This commit is contained in:
Raul Marin 2019-11-05 16:53:25 +01:00
parent e2beefdb53
commit c9b01592e7
3 changed files with 35 additions and 6 deletions

View File

@ -186,7 +186,10 @@ BEGIN
array_to_string(carto_columns_expression || rest_of_cols, ','),
src_table
);
EXCEPTION WHEN OTHERS THEN
EXCEPTION
WHEN insufficient_privilege THEN
RAISE EXCEPTION 'Could not import table "%" as "%": "%" already exists', remote_table, local_name, local_name;
WHEN OTHERS THEN
RAISE EXCEPTION 'Could not import table "%" as "%": %', remote_table, local_name, SQLERRM;
END;

View File

@ -242,11 +242,29 @@ SELECT cartodb.CDB_Federated_Table_Unregister(
remote_table => 'remote_geom'
);
-- Try to register with invalid / NULL id
-- Try to register with invalid / NULL geom_column
-- Try to register with invalid / NULL webmercator_column
-- Try to register the same table twice (different name) should fail
-- Check that conflict is handled nicely (target view already exists)
\echo '## Target conflict is handled nicely: Table'
CREATE TABLE localtable (a integer);
SELECT cartodb.CDB_Federated_Table_Register(
server => 'loopback',
remote_schema => 'remote_schema',
remote_table => 'remote_geom',
id_column => 'id',
geom_column => 'geom',
local_name => 'localtable');
\echo '## Target conflict is handled nicely: View'
CREATE VIEW localtable2 AS Select * from localtable;
SELECT cartodb.CDB_Federated_Table_Register(
server => 'loopback',
remote_schema => 'remote_schema',
remote_table => 'remote_geom',
id_column => 'id',
geom_column => 'geom',
local_name => 'localtable2');
DROP VIEW localtable2;
DROP TABLE localtable;
-- Try permissions tricks

View File

@ -53,4 +53,12 @@ ERROR: non geometry column "Does not exists"
## Registering a table: NULL webmercator_column is OK
## Target conflict is handled nicely: Table
CREATE TABLE
ERROR: Could not import table "remote_geom" as "localtable": "localtable" already exists
## Target conflict is handled nicely: View
CREATE VIEW
ERROR: Could not import table "remote_geom" as "localtable2": "localtable2" already exists
DROP VIEW
DROP TABLE
D1|