Exclude certain columns from sync if instructed to do so
For the Geocoding (and in general for LDS use cases) it may come in handy to exclude geometry columns from the list of stuff to syncrhonize. Otherwise they may be lost, overwritten with NULL values.
This commit is contained in:
parent
2f8ea7e4ea
commit
a2723a3c90
@ -80,7 +80,7 @@ $$ LANGUAGE sql VOLATILE PARALLEL UNSAFE;
|
|||||||
SELECT CDB_SyncTable('radar_stations', 'public', 'syncdest');
|
SELECT CDB_SyncTable('radar_stations', 'public', 'syncdest');
|
||||||
|
|
||||||
*/
|
*/
|
||||||
CREATE OR REPLACE FUNCTION CDB_SyncTable(src_table REGCLASS, dst_schema REGNAMESPACE, dst_table NAME)
|
CREATE OR REPLACE FUNCTION CDB_SyncTable(src_table REGCLASS, dst_schema REGNAMESPACE, dst_table NAME, skip_cols NAME[] = '{}')
|
||||||
RETURNS void
|
RETURNS void
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -106,8 +106,10 @@ BEGIN
|
|||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Get the list of columns from the source table, excluding cartodb_id
|
skip_cols := skip_cols || '{cartodb_id}';
|
||||||
SELECT ARRAY(SELECT quote_ident(c) FROM _CDB_GetColumns(src_table) as c WHERE c <> 'cartodb_id') INTO colnames;
|
|
||||||
|
-- Get the list of columns from the source table, excluding skip_cols
|
||||||
|
SELECT ARRAY(SELECT quote_ident(c) FROM _CDB_GetColumns(src_table) as c EXCEPT SELECT unnest(skip_cols)) INTO colnames;
|
||||||
quoted_colnames := array_to_string(colnames, ',');
|
quoted_colnames := array_to_string(colnames, ',');
|
||||||
|
|
||||||
src_hash_table_name := __CDB_GenerateUniqueName('src_sync');
|
src_hash_table_name := __CDB_GenerateUniqueName('src_sync');
|
||||||
|
@ -40,5 +40,19 @@ SELECT * FROM test_sync_source ORDER BY cartodb_id;
|
|||||||
SELECT * FROM test_sync_dest ORDER BY cartodb_id;
|
SELECT * FROM test_sync_dest ORDER BY cartodb_id;
|
||||||
|
|
||||||
|
|
||||||
|
\echo 'It shall exclude geom columns if instructed to do so'
|
||||||
|
\set QUIET on
|
||||||
|
SET client_min_messages TO error;
|
||||||
|
SELECT cartodb.CDB_SetUserQuotaInBytes(0); -- Set user quota to infinite
|
||||||
|
SELECT cartodb.CDB_CartodbfyTable('test_sync_source');
|
||||||
|
SELECT cartodb.CDB_CartodbfyTable('test_sync_dest');
|
||||||
|
UPDATE test_sync_dest SET the_geom = cartodb.CDB_LatLng(lat, lon); -- A "gecoding"
|
||||||
|
\set QUIET off
|
||||||
|
SET client_min_messages TO notice;
|
||||||
|
SELECT cartodb.CDB_SyncTable('test_sync_source', 'public', 'test_sync_dest', '{the_geom, the_geom_webmercator}');
|
||||||
|
SELECT * FROM test_sync_source;
|
||||||
|
SELECT * FROM test_sync_dest;
|
||||||
|
|
||||||
|
|
||||||
-- Cleanup
|
-- Cleanup
|
||||||
ROLLBACK;
|
ROLLBACK;
|
||||||
|
@ -37,4 +37,25 @@ Sanity check: the end result is the same source table
|
|||||||
2|2|2|bar
|
2|2|2|bar
|
||||||
4|4|4|cantaloupe
|
4|4|4|cantaloupe
|
||||||
5|5|5|sandia
|
5|5|5|sandia
|
||||||
|
It shall exclude geom columns if instructed to do so
|
||||||
|
0
|
||||||
|
test_sync_source
|
||||||
|
test_sync_dest
|
||||||
|
SET
|
||||||
|
NOTICE: relation "test_sync_dest" already exists, skipping
|
||||||
|
NOTICE: cdb_invalidate_varnish(public.test_sync_dest) called
|
||||||
|
NOTICE: DELETED 0 row(s)
|
||||||
|
NOTICE: cdb_invalidate_varnish(public.test_sync_dest) called
|
||||||
|
NOTICE: INSERTED 0 row(s)
|
||||||
|
NOTICE: cdb_invalidate_varnish(public.test_sync_dest) called
|
||||||
|
NOTICE: MODIFIED 0 row(s)
|
||||||
|
|
||||||
|
1|||1|1|foo
|
||||||
|
2|||2|2|bar
|
||||||
|
5|||5|5|sandia
|
||||||
|
4|||4|4|cantaloupe
|
||||||
|
1|0101000020E6100000000000000000F03F000000000000F03F|0101000020110F0000DB0B4ADA772DFB402B432E49D22DFB40|1|1|foo
|
||||||
|
2|0101000020E610000000000000000000400000000000000040|0101000020110F00003C0C4ADA772D0B4177F404ABE12E0B41|2|2|bar
|
||||||
|
5|0101000020E610000000000000000014400000000000001440|0101000020110F000099476EE86AFC20413E7EB983F2012141|5|5|sandia
|
||||||
|
4|0101000020E610000000000000000010400000000000001040|0101000020110F00003C0C4ADA772D1B4160AB497020331B41|4|4|cantaloupe
|
||||||
ROLLBACK
|
ROLLBACK
|
||||||
|
Loading…
Reference in New Issue
Block a user