From 1028b24333ee01e14e8d58b2610dcc3084759922 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 1 Jul 2019 14:48:42 +0200 Subject: [PATCH] Fix cartodb schema references --- scripts-available/CDB_SyncTable.sql | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scripts-available/CDB_SyncTable.sql b/scripts-available/CDB_SyncTable.sql index 521495a..c7979c3 100644 --- a/scripts-available/CDB_SyncTable.sql +++ b/scripts-available/CDB_SyncTable.sql @@ -3,9 +3,9 @@ Sample usage: - SELECT cartodb._CDB_GetColumns('public.films'); + SELECT @extschema@._CDB_GetColumns('public.films'); */ -CREATE OR REPLACE FUNCTION cartodb._CDB_GetColumns(src_table REGCLASS) +CREATE OR REPLACE FUNCTION @extschema@._CDB_GetColumns(src_table REGCLASS) RETURNS SETOF NAME AS $$ SELECT @@ -35,9 +35,9 @@ $$ LANGUAGE sql STABLE PARALLEL UNSAFE; Example of usage: - SELECT cartodb.__CDB_GetUpdateSetClause('{the_geom, id, elevation}', 'changed'); + SELECT @extschema@.__CDB_GetUpdateSetClause('{the_geom, id, elevation}', 'changed'); */ -CREATE OR REPLACE FUNCTION cartodb.__CDB_GetUpdateSetClause(colnames TEXT[], update_source TEXT) +CREATE OR REPLACE FUNCTION @extschema@.__CDB_GetUpdateSetClause(colnames TEXT[], update_source TEXT) RETURNS TEXT AS $$ DECLARE @@ -58,10 +58,10 @@ $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE; Example of usage: - SELECT cartodb.__CDB_GenerateUniqueName('src_sync'); --> src_sync_718794_120106 + SELECT @extschema@.__CDB_GenerateUniqueName('src_sync'); --> src_sync_718794_120106 */ -CREATE OR REPLACE FUNCTION cartodb.__CDB_GenerateUniqueName(prefix TEXT) +CREATE OR REPLACE FUNCTION @extschema@.__CDB_GenerateUniqueName(prefix TEXT) RETURNS NAME AS $$ SELECT format('%s_%s_%s', prefix, txid_current(), (random()*1000000)::int)::NAME; @@ -81,7 +81,7 @@ $$ LANGUAGE sql VOLATILE PARALLEL UNSAFE; SELECT cartodb.CDB_SyncTable('test_sync_source', 'public', 'test_sync_dest', '{the_geom, the_geom_webmercator}'); */ -CREATE OR REPLACE FUNCTION cartodb.CDB_SyncTable(src_table REGCLASS, dst_schema REGNAMESPACE, dst_table NAME, skip_cols NAME[] = '{}') +CREATE OR REPLACE FUNCTION @extschema@.CDB_SyncTable(src_table REGCLASS, dst_schema REGNAMESPACE, dst_table NAME, skip_cols NAME[] = '{}') RETURNS void AS $$ DECLARE @@ -112,11 +112,11 @@ BEGIN skip_cols := skip_cols || '{cartodb_id}'; -- Get the list of columns from the source table, excluding skip_cols - SELECT ARRAY(SELECT quote_ident(c) FROM cartodb._CDB_GetColumns(src_table) as c EXCEPT SELECT unnest(skip_cols)) INTO colnames; + SELECT ARRAY(SELECT quote_ident(c) FROM @extschema@._CDB_GetColumns(src_table) as c EXCEPT SELECT unnest(skip_cols)) INTO colnames; quoted_colnames := array_to_string(colnames, ','); - src_hash_table_name := cartodb.__CDB_GenerateUniqueName('src_sync'); - dst_hash_table_name := cartodb.__CDB_GenerateUniqueName('dst_sync'); + src_hash_table_name := @extschema@.__CDB_GenerateUniqueName('src_sync'); + dst_hash_table_name := @extschema@.__CDB_GenerateUniqueName('dst_sync'); EXECUTE format('CREATE TEMP TABLE %I(cartodb_id BIGINT, hash TEXT) ON COMMIT DROP', src_hash_table_name); EXECUTE format('CREATE TEMP TABLE %I(cartodb_id BIGINT, hash TEXT) ON COMMIT DROP', dst_hash_table_name); @@ -159,7 +159,7 @@ BEGIN -- Deal with modified rows: ids in source and dest but different hashes t := clock_timestamp(); - update_set_clause := cartodb.__CDB_GetUpdateSetClause(colnames, 'changed'); + update_set_clause := @extschema@.__CDB_GetUpdateSetClause(colnames, 'changed'); EXECUTE format(' UPDATE %1$s dst SET %2$s FROM (