Fix cartodb schema references
This commit is contained in:
parent
4d1c4f6a22
commit
1028b24333
@ -3,9 +3,9 @@
|
|||||||
|
|
||||||
Sample usage:
|
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
|
RETURNS SETOF NAME
|
||||||
AS $$
|
AS $$
|
||||||
SELECT
|
SELECT
|
||||||
@ -35,9 +35,9 @@ $$ LANGUAGE sql STABLE PARALLEL UNSAFE;
|
|||||||
|
|
||||||
Example of usage:
|
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
|
RETURNS TEXT
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -58,10 +58,10 @@ $$ LANGUAGE plpgsql IMMUTABLE PARALLEL SAFE;
|
|||||||
|
|
||||||
Example of usage:
|
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
|
RETURNS NAME
|
||||||
AS $$
|
AS $$
|
||||||
SELECT format('%s_%s_%s', prefix, txid_current(), (random()*1000000)::int)::NAME;
|
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}');
|
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
|
RETURNS void
|
||||||
AS $$
|
AS $$
|
||||||
DECLARE
|
DECLARE
|
||||||
@ -112,11 +112,11 @@ BEGIN
|
|||||||
skip_cols := skip_cols || '{cartodb_id}';
|
skip_cols := skip_cols || '{cartodb_id}';
|
||||||
|
|
||||||
-- Get the list of columns from the source table, excluding skip_cols
|
-- 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, ',');
|
quoted_colnames := array_to_string(colnames, ',');
|
||||||
|
|
||||||
src_hash_table_name := cartodb.__CDB_GenerateUniqueName('src_sync');
|
src_hash_table_name := @extschema@.__CDB_GenerateUniqueName('src_sync');
|
||||||
dst_hash_table_name := cartodb.__CDB_GenerateUniqueName('dst_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', src_hash_table_name);
|
||||||
EXECUTE format('CREATE TEMP TABLE %I(cartodb_id BIGINT, hash TEXT) ON COMMIT DROP', dst_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
|
-- Deal with modified rows: ids in source and dest but different hashes
|
||||||
t := clock_timestamp();
|
t := clock_timestamp();
|
||||||
update_set_clause := cartodb.__CDB_GetUpdateSetClause(colnames, 'changed');
|
update_set_clause := @extschema@.__CDB_GetUpdateSetClause(colnames, 'changed');
|
||||||
EXECUTE format('
|
EXECUTE format('
|
||||||
UPDATE %1$s dst SET %2$s
|
UPDATE %1$s dst SET %2$s
|
||||||
FROM (
|
FROM (
|
||||||
|
Loading…
Reference in New Issue
Block a user