Merge branch 'master' into great_circle_generator
This commit is contained in:
commit
f43d1cc3c4
5
Makefile
5
Makefile
@ -1,7 +1,7 @@
|
|||||||
# cartodb/Makefile
|
# cartodb/Makefile
|
||||||
|
|
||||||
EXTENSION = cartodb
|
EXTENSION = cartodb
|
||||||
EXTVERSION = 0.11.1
|
EXTVERSION = 0.11.3
|
||||||
|
|
||||||
SED = sed
|
SED = sed
|
||||||
|
|
||||||
@ -11,6 +11,7 @@ CDBSCRIPTS = \
|
|||||||
scripts-available/CDB_DDLTriggers.sql \
|
scripts-available/CDB_DDLTriggers.sql \
|
||||||
scripts-available/CDB_ExtensionPost.sql \
|
scripts-available/CDB_ExtensionPost.sql \
|
||||||
scripts-available/CDB_ExtensionUtils.sql \
|
scripts-available/CDB_ExtensionUtils.sql \
|
||||||
|
scripts-available/CDB_Helper.sql \
|
||||||
$(END)
|
$(END)
|
||||||
|
|
||||||
UPGRADABLE = \
|
UPGRADABLE = \
|
||||||
@ -52,6 +53,8 @@ UPGRADABLE = \
|
|||||||
0.10.2 \
|
0.10.2 \
|
||||||
0.11.0 \
|
0.11.0 \
|
||||||
0.11.1 \
|
0.11.1 \
|
||||||
|
0.11.2 \
|
||||||
|
0.11.3 \
|
||||||
$(EXTVERSION)dev \
|
$(EXTVERSION)dev \
|
||||||
$(EXTVERSION)next \
|
$(EXTVERSION)next \
|
||||||
$(END)
|
$(END)
|
||||||
|
12
NEWS.md
12
NEWS.md
@ -1,6 +1,18 @@
|
|||||||
next (2015-mm-dd)
|
next (2015-mm-dd)
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
0.11.3 (2015-10-27)
|
||||||
|
-------------------
|
||||||
|
* Added CDB_Helper.sql [#173](https://github.com/CartoDB/cartodb-postgresql/pull/173)
|
||||||
|
* Added _CDB_Unique_Identifier for creating UTF8 aware unique identifiers
|
||||||
|
* Added _CDB_Unique_Column_Identifier for creating UTF8 aware unique identifiers for columns
|
||||||
|
* Added _CDB_Octet_Truncate that truncates text to a certain amount of octets.
|
||||||
|
|
||||||
|
0.11.2 (2015-10-19)
|
||||||
|
-------------------
|
||||||
|
* Fix schema not being specified on pg_get_serial_sequence [#170](https://github.com/CartoDB/cartodb-postgresql/pull/170)
|
||||||
|
* Log invalidation function call duration in seconds [#163](https://github.com/CartoDB/cartodb-postgresql/pull/163)
|
||||||
|
|
||||||
0.11.1 (2015-10-06)
|
0.11.1 (2015-10-06)
|
||||||
-------------------
|
-------------------
|
||||||
* Added CDB_DateToNumber(timestamp with time zone) [#169](https://github.com/CartoDB/cartodb-postgresql/pull/169)
|
* Added CDB_DateToNumber(timestamp with time zone) [#169](https://github.com/CartoDB/cartodb-postgresql/pull/169)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
-- Depends on:
|
-- Depends on:
|
||||||
|
-- * CDB_Helper.sql
|
||||||
-- * CDB_ExtensionUtils.sql
|
-- * CDB_ExtensionUtils.sql
|
||||||
-- * CDB_TransformToWebmercator.sql
|
-- * CDB_TransformToWebmercator.sql
|
||||||
-- * CDB_TableMetadata.sql
|
-- * CDB_TableMetadata.sql
|
||||||
@ -427,8 +428,9 @@ END;
|
|||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
-- Find a unique relation name in the given schema, starting from the
|
-- DEPRECATED: Use _CDB_Unique_Identifier since it's UTF8 Safe and length
|
||||||
-- template given. If the template is already unique, just return it;
|
-- aware. Find a unique relation name in the given schema, starting from the
|
||||||
|
-- template given. If the template is already unique, just return it;
|
||||||
-- otherwise, append an increasing integer until you find a unique variant.
|
-- otherwise, append an increasing integer until you find a unique variant.
|
||||||
CREATE OR REPLACE FUNCTION _CDB_Unique_Relation_Name(schemaname TEXT, relationname TEXT)
|
CREATE OR REPLACE FUNCTION _CDB_Unique_Relation_Name(schemaname TEXT, relationname TEXT)
|
||||||
RETURNS TEXT
|
RETURNS TEXT
|
||||||
@ -439,36 +441,15 @@ DECLARE
|
|||||||
newrelname TEXT;
|
newrelname TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
i := 0;
|
RAISE EXCEPTION '_CDB_Unique_Relation_Name is DEPRECATED. Use _CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)';
|
||||||
newrelname := relationname;
|
|
||||||
LOOP
|
|
||||||
|
|
||||||
SELECT c.relname, n.nspname
|
|
||||||
INTO rec
|
|
||||||
FROM pg_class c
|
|
||||||
JOIN pg_namespace n ON c.relnamespace = n.oid
|
|
||||||
WHERE c.relname = newrelname
|
|
||||||
AND n.nspname = schemaname;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
RETURN newrelname;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
i := i + 1;
|
|
||||||
newrelname := relationname || '_' || i;
|
|
||||||
|
|
||||||
IF i > 100 THEN
|
|
||||||
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Relation_Name');
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
END LOOP;
|
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
-- Find a unique column name in the given relation, starting from the
|
-- DEPRECATED: Use _CDB_Unique_Column_Identifier since it's UTF8 Safe and length
|
||||||
-- column name given. If the column name is already unique, just return it;
|
-- aware. Find a unique column name in the given relation, starting from the
|
||||||
|
-- column name given. If the column name is already unique, just return it;
|
||||||
-- otherwise, append an increasing integer until you find a unique variant.
|
-- otherwise, append an increasing integer until you find a unique variant.
|
||||||
CREATE OR REPLACE FUNCTION _CDB_Unique_Column_Name(reloid REGCLASS, columnname TEXT)
|
CREATE OR REPLACE FUNCTION _CDB_Unique_Column_Name(reloid REGCLASS, columnname TEXT)
|
||||||
RETURNS TEXT
|
RETURNS TEXT
|
||||||
@ -479,32 +460,8 @@ DECLARE
|
|||||||
newcolname TEXT;
|
newcolname TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
i := 0;
|
RAISE EXCEPTION '_CDB_Unique_Column_Name is DEPRECATED. Use _CDB_Unique_Column_Identifier(prefix TEXT, relname TEXT, suffix TEXT, reloid REGCLASS DEFAULT NULL)';
|
||||||
newcolname := columnname;
|
|
||||||
LOOP
|
|
||||||
|
|
||||||
SELECT a.attname
|
|
||||||
INTO rec
|
|
||||||
FROM pg_class c
|
|
||||||
JOIN pg_attribute a ON a.attrelid = c.oid
|
|
||||||
WHERE NOT a.attisdropped
|
|
||||||
AND a.attnum > 0
|
|
||||||
AND c.oid = reloid
|
|
||||||
AND a.attname = newcolname;
|
|
||||||
|
|
||||||
IF NOT FOUND THEN
|
|
||||||
RETURN newcolname;
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
i := i + 1;
|
|
||||||
newcolname := columnname || '_' || i;
|
|
||||||
|
|
||||||
IF i > 100 THEN
|
|
||||||
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Name');
|
|
||||||
END IF;
|
|
||||||
|
|
||||||
END LOOP;
|
|
||||||
|
|
||||||
END;
|
END;
|
||||||
$$ LANGUAGE 'plpgsql';
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
@ -589,7 +546,7 @@ BEGIN
|
|||||||
PERFORM _CDB_SQL(
|
PERFORM _CDB_SQL(
|
||||||
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
||||||
reloid::text, rec.attname,
|
reloid::text, rec.attname,
|
||||||
_CDB_Unique_Column_Name(reloid, const.pkey)),
|
cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
||||||
'_CDB_Has_Usable_Primary_ID');
|
'_CDB_Has_Usable_Primary_ID');
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
@ -606,7 +563,7 @@ BEGIN
|
|||||||
|
|
||||||
PERFORM _CDB_SQL(
|
PERFORM _CDB_SQL(
|
||||||
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
Format('ALTER TABLE %s RENAME COLUMN %s TO %I',
|
||||||
reloid::text, rec.attname, _CDB_Unique_Column_Name(reloid, const.pkey)),
|
reloid::text, rec.attname, cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)),
|
||||||
'_CDB_Has_Usable_Primary_ID');
|
'_CDB_Has_Usable_Primary_ID');
|
||||||
|
|
||||||
END IF;
|
END IF;
|
||||||
@ -772,7 +729,7 @@ BEGIN
|
|||||||
WHEN others THEN
|
WHEN others THEN
|
||||||
IF SQLERRM = 'parse error - invalid geometry' THEN
|
IF SQLERRM = 'parse error - invalid geometry' THEN
|
||||||
text_geom_column := false;
|
text_geom_column := false;
|
||||||
str := _CDB_Unique_Column_Name(reloid, r1.attname);
|
str := cartodb._CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
||||||
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
||||||
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
||||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
||||||
@ -784,7 +741,7 @@ BEGIN
|
|||||||
|
|
||||||
-- Just change its name so we can write a new column into that name.
|
-- Just change its name so we can write a new column into that name.
|
||||||
ELSE
|
ELSE
|
||||||
str := _CDB_Unique_Column_Name(reloid, r1.attname);
|
str := cartodb._CDB_Unique_Column_Identifier(NULL, r1.attname, NULL, reloid);
|
||||||
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %I', reloid::text, r1.attname, str);
|
||||||
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom');
|
||||||
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %',
|
||||||
@ -854,8 +811,7 @@ DECLARE
|
|||||||
destname TEXT;
|
destname TEXT;
|
||||||
destseq TEXT;
|
destseq TEXT;
|
||||||
destseqmax INTEGER;
|
destseqmax INTEGER;
|
||||||
|
|
||||||
salt TEXT := md5(random()::text || now());
|
|
||||||
copyname TEXT;
|
copyname TEXT;
|
||||||
|
|
||||||
column_name_sql TEXT;
|
column_name_sql TEXT;
|
||||||
@ -961,19 +917,18 @@ BEGIN
|
|||||||
-- Put the primary key sequence in the right schema
|
-- Put the primary key sequence in the right schema
|
||||||
-- If the new table is not moving, better ensure the sequence name
|
-- If the new table is not moving, better ensure the sequence name
|
||||||
-- is unique
|
-- is unique
|
||||||
destseq := relname || '_' || const.pkey || '_seq';
|
destseq := cartodb._CDB_Unique_Identifier(NULL, relname, '_' || const.pkey || '_seq', destschema);
|
||||||
destseq := _CDB_Unique_Relation_Name(destschema, destseq);
|
|
||||||
destseq := Format('%I.%I', destschema, destseq);
|
destseq := Format('%I.%I', destschema, destseq);
|
||||||
PERFORM _CDB_SQL(Format('CREATE SEQUENCE %s', destseq), '_CDB_Rewrite_Table');
|
PERFORM _CDB_SQL(Format('CREATE SEQUENCE %s', destseq), '_CDB_Rewrite_Table');
|
||||||
|
|
||||||
-- Salt a temporary table name if we are re-writing in place
|
-- Temporary table name if we are re-writing in place
|
||||||
-- Note copyname is already escaped and safe to use as identifier
|
-- Note copyname is already escaped and safe to use as identifier
|
||||||
IF destschema = relschema THEN
|
IF destschema = relschema THEN
|
||||||
copyname := Format('%I.%I', destschema, Format('%s_%s', destname, salt));
|
copyname := Format('%I.%I', destschema, cartodb._CDB_Unique_Identifier(NULL, destname, NULL), destschema);
|
||||||
ELSE
|
ELSE
|
||||||
copyname := Format('%I.%I', destschema, destname);
|
copyname := Format('%I.%I', destschema, destname);
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
-- Start building the SQL!
|
-- Start building the SQL!
|
||||||
sql := Format('CREATE TABLE %s AS SELECT ', copyname);
|
sql := Format('CREATE TABLE %s AS SELECT ', copyname);
|
||||||
|
|
||||||
|
@ -163,7 +163,7 @@ BEGIN
|
|||||||
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
group_role := cartodb._CDB_Group_GroupRole(group_name);
|
||||||
FOR column_name IN EXECUTE 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = current_database() AND TABLE_SCHEMA = $1 AND TABLE_NAME = $2 AND COLUMN_DEFAULT LIKE ''nextval%''' USING username, table_name
|
FOR column_name IN EXECUTE 'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = current_database() AND TABLE_SCHEMA = $1 AND TABLE_NAME = $2 AND COLUMN_DEFAULT LIKE ''nextval%''' USING username, table_name
|
||||||
LOOP
|
LOOP
|
||||||
EXECUTE 'SELECT PG_GET_SERIAL_SEQUENCE($1, $2)' USING table_name, column_name INTO sequence_name;
|
EXECUTE format('SELECT PG_GET_SERIAL_SEQUENCE(''%I.%I'', ''%I'')', username, table_name, column_name) INTO sequence_name;
|
||||||
IF sequence_name IS NOT NULL THEN
|
IF sequence_name IS NOT NULL THEN
|
||||||
IF do_grant THEN
|
IF do_grant THEN
|
||||||
-- Here %s is needed since sequence_name has quotes
|
-- Here %s is needed since sequence_name has quotes
|
||||||
|
156
scripts-available/CDB_Helper.sql
Normal file
156
scripts-available/CDB_Helper.sql
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
-- UTF8 safe and length aware. Find a unique identifier with a given prefix
|
||||||
|
-- and/or suffix and withing a schema. If a schema is not specified, the identifier
|
||||||
|
-- is guaranteed to be unique for all schemas.
|
||||||
|
CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Identifier(prefix TEXT, relname TEXT, suffix TEXT, schema TEXT DEFAULT NULL)
|
||||||
|
RETURNS TEXT
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
maxlen CONSTANT INTEGER := 63;
|
||||||
|
|
||||||
|
rec RECORD;
|
||||||
|
usedspace INTEGER;
|
||||||
|
ident TEXT;
|
||||||
|
origident TEXT;
|
||||||
|
candrelname TEXT;
|
||||||
|
|
||||||
|
i INTEGER;
|
||||||
|
BEGIN
|
||||||
|
-- Accounts for the _XX incremental suffix in case the identifier is taken
|
||||||
|
usedspace := 3;
|
||||||
|
usedspace := usedspace + coalesce(octet_length(prefix), 0);
|
||||||
|
usedspace := usedspace + coalesce(octet_length(suffix), 0);
|
||||||
|
|
||||||
|
candrelname := _CDB_Octet_Truncate(relname, maxlen - usedspace);
|
||||||
|
|
||||||
|
IF candrelname = '' THEN
|
||||||
|
PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Identifier');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
ident := coalesce(prefix, '') || candrelname || coalesce(suffix, '');
|
||||||
|
|
||||||
|
i := 0;
|
||||||
|
origident := ident;
|
||||||
|
|
||||||
|
WHILE i < 100 LOOP
|
||||||
|
IF schema IS NOT NULL THEN
|
||||||
|
SELECT c.relname, n.nspname
|
||||||
|
INTO rec
|
||||||
|
FROM pg_class c
|
||||||
|
JOIN pg_namespace n ON c.relnamespace = n.oid
|
||||||
|
WHERE c.relname = ident
|
||||||
|
AND n.nspname = schema;
|
||||||
|
ELSE
|
||||||
|
SELECT c.relname, n.nspname
|
||||||
|
INTO rec
|
||||||
|
FROM pg_class c
|
||||||
|
JOIN pg_namespace n ON c.relnamespace = n.oid
|
||||||
|
WHERE c.relname = ident;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
IF NOT FOUND THEN
|
||||||
|
RETURN ident;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
ident := origident || '_' || i;
|
||||||
|
i := i + 1;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Identifier');
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
|
-- UTF8 safe and length aware. Find a unique identifier for a column with a given prefix
|
||||||
|
-- and/or suffix based on colname and within a relation specified via reloid.
|
||||||
|
CREATE OR REPLACE FUNCTION cartodb._CDB_Unique_Column_Identifier(prefix TEXT, colname TEXT, suffix TEXT, reloid REGCLASS)
|
||||||
|
RETURNS TEXT
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
maxlen CONSTANT INTEGER := 63;
|
||||||
|
|
||||||
|
rec RECORD;
|
||||||
|
candcolname TEXT;
|
||||||
|
usedspace INTEGER;
|
||||||
|
ident TEXT;
|
||||||
|
origident TEXT;
|
||||||
|
|
||||||
|
i INTEGER;
|
||||||
|
BEGIN
|
||||||
|
-- Accounts for the _XX incremental suffix in case the identifier is taken
|
||||||
|
usedspace := 3;
|
||||||
|
usedspace := usedspace + coalesce(octet_length(prefix), 0);
|
||||||
|
usedspace := usedspace + coalesce(octet_length(suffix), 0);
|
||||||
|
|
||||||
|
candcolname := _CDB_Octet_Truncate(colname, maxlen - usedspace);
|
||||||
|
|
||||||
|
IF candcolname = '' THEN
|
||||||
|
PERFORM _CDB_Error('prefixes are to long to generate a valid identifier', '_CDB_Unique_Column_Identifier');
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
ident := coalesce(prefix, '') || candcolname || coalesce(suffix, '');
|
||||||
|
|
||||||
|
i := 0;
|
||||||
|
origident := ident;
|
||||||
|
|
||||||
|
WHILE i < 100 LOOP
|
||||||
|
SELECT a.attname
|
||||||
|
INTO rec
|
||||||
|
FROM pg_class c
|
||||||
|
JOIN pg_attribute a ON a.attrelid = c.oid
|
||||||
|
WHERE NOT a.attisdropped
|
||||||
|
AND a.attnum > 0
|
||||||
|
AND c.oid = reloid
|
||||||
|
AND a.attname = ident;
|
||||||
|
|
||||||
|
IF NOT FOUND THEN
|
||||||
|
RETURN ident;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
ident := origident || '_' || i;
|
||||||
|
i := i + 1;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
PERFORM _CDB_Error('looping too far', '_CDB_Unique_Column_Identifier');
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
||||||
|
|
||||||
|
|
||||||
|
-- Truncates a given string to a max_octets octets taking care
|
||||||
|
-- not to leave characters in half. UTF8 safe.
|
||||||
|
CREATE OR REPLACE FUNCTION cartodb._CDB_Octet_Truncate(string TEXT, max_octets INTEGER)
|
||||||
|
RETURNS TEXT
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
extcharlen CONSTANT INTEGER := octet_length('ñ');
|
||||||
|
|
||||||
|
expected INTEGER;
|
||||||
|
examined INTEGER;
|
||||||
|
strlen INTEGER;
|
||||||
|
|
||||||
|
i INTEGER;
|
||||||
|
BEGIN
|
||||||
|
|
||||||
|
IF max_octets <= 0 THEN
|
||||||
|
RETURN '';
|
||||||
|
ELSIF max_octets >= octet_length(string) THEN
|
||||||
|
RETURN string;
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
strlen := char_length(string);
|
||||||
|
|
||||||
|
expected := char_length(string);
|
||||||
|
examined := octet_length(string);
|
||||||
|
|
||||||
|
IF expected = examined THEN
|
||||||
|
RETURN left(string, max_octets);
|
||||||
|
END IF;
|
||||||
|
|
||||||
|
i := max_octets / extcharlen;
|
||||||
|
|
||||||
|
WHILE octet_length(left(string, i)) <= max_octets LOOP
|
||||||
|
i := i + 1;
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
RETURN left(string, (i - 1));
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE 'plpgsql';
|
@ -64,6 +64,10 @@ DECLARE
|
|||||||
tabname TEXT;
|
tabname TEXT;
|
||||||
rec RECORD;
|
rec RECORD;
|
||||||
found BOOL;
|
found BOOL;
|
||||||
|
function_start timestamptz;
|
||||||
|
function_end timestamptz;
|
||||||
|
function_duration float;
|
||||||
|
log_error_verbosity_value text;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
IF TG_OP = 'UPDATE' or TG_OP = 'INSERT' THEN
|
||||||
@ -72,6 +76,8 @@ BEGIN
|
|||||||
tabname = OLD.tabname;
|
tabname = OLD.tabname;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
|
function_start := clock_timestamp();
|
||||||
|
|
||||||
-- Notify table data update
|
-- Notify table data update
|
||||||
-- This needs a little bit more of research regarding security issues
|
-- This needs a little bit more of research regarding security issues
|
||||||
-- see https://github.com/CartoDB/cartodb/pull/241
|
-- see https://github.com/CartoDB/cartodb/pull/241
|
||||||
@ -105,7 +111,14 @@ BEGIN
|
|||||||
EXIT;
|
EXIT;
|
||||||
END LOOP;
|
END LOOP;
|
||||||
IF NOT found THEN RAISE WARNING 'Missing cdb_invalidate_varnish()'; END IF;
|
IF NOT found THEN RAISE WARNING 'Missing cdb_invalidate_varnish()'; END IF;
|
||||||
|
|
||||||
|
function_end := clock_timestamp();
|
||||||
|
SELECT extract(epoch from (function_end - function_start)) INTO function_duration;
|
||||||
|
SELECT setting INTO log_error_verbosity_value FROM pg_settings WHERE name='log_error_verbosity';
|
||||||
|
SET log_error_verbosity=TERSE;
|
||||||
|
RAISE LOG 'invalidation_duration: %', function_duration::text;
|
||||||
|
PERFORM 'SET log_error_verbosity= ' || log_error_verbosity_value;
|
||||||
|
|
||||||
RETURN NULL;
|
RETURN NULL;
|
||||||
END;
|
END;
|
||||||
$$
|
$$
|
||||||
|
@ -291,7 +291,7 @@ INSERT INTO test VALUES
|
|||||||
(NULL),
|
(NULL),
|
||||||
(3);
|
(3);
|
||||||
SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148');
|
SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148');
|
||||||
SELECT cartodb_id, cartodb_id_1 from test;
|
SELECT cartodb_id, cartodb_id_0 from test;
|
||||||
DROP TABLE test;
|
DROP TABLE test;
|
||||||
|
|
||||||
-- Table with non unique cartodb_id
|
-- Table with non unique cartodb_id
|
||||||
@ -303,7 +303,7 @@ INSERT INTO test VALUES
|
|||||||
(2),
|
(2),
|
||||||
(2);
|
(2);
|
||||||
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148');
|
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148');
|
||||||
SELECT cartodb_id, cartodb_id_1 from test;
|
SELECT cartodb_id, cartodb_id_0 from test;
|
||||||
DROP TABLE test;
|
DROP TABLE test;
|
||||||
|
|
||||||
-- Table with non unique and null cartodb_id
|
-- Table with non unique and null cartodb_id
|
||||||
@ -316,7 +316,7 @@ INSERT INTO test VALUES
|
|||||||
(NULL),
|
(NULL),
|
||||||
(2);
|
(2);
|
||||||
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148');
|
SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148');
|
||||||
SELECT cartodb_id, cartodb_id_1 from test;
|
SELECT cartodb_id, cartodb_id_0 from test;
|
||||||
DROP TABLE test;
|
DROP TABLE test;
|
||||||
|
|
||||||
|
|
||||||
|
128
test/CDB_HelperTest.sql
Normal file
128
test/CDB_HelperTest.sql
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
-- Test unique identifier creation with normal length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'relname', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with normal length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'relname', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with normal length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'relname', '_suffix');
|
||||||
|
|
||||||
|
-- Test unique identifier creation with long length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with long length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL);
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE prefix_largolargolargolargolargolargolargolargolargolargolar (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL);
|
||||||
|
DROP TABLE prefix_largolargolargolargolargolargolargolargolargolargolar;
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with long length normal relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix');
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE largolargolargolargolargolargolargolargolargolargolar_suffix (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix');
|
||||||
|
DROP TABLE largolargolargolargolargolargolargolargolargolargolar_suffix;
|
||||||
|
|
||||||
|
-- Test unique identifier creation with normal length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'piraña', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with normal length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'piraña', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with normal length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'piraña', '_suffix');
|
||||||
|
|
||||||
|
-- Test unique identifier creation with long length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with long length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL);
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL);
|
||||||
|
DROP TABLE prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi;
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with long length UTF8 relname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix');
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix');
|
||||||
|
DROP TABLE piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix;
|
||||||
|
|
||||||
|
CREATE TABLE test (name text);
|
||||||
|
-- Test unique identifier creation with normal length normal colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'colname', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with normal length normal colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'colname', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with normal length normal colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'colname', '_suffix', 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with long length normal colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with long length normal colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL, 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE test (prefix_largolargolargolargolargolargolargolargolargolargolar text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'largolargolargolargolargolargolargolargolargolargolargolargolar', NULL, 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with long length normal colname
|
||||||
|
CREATE TABLE test (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix', 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE test (largolargolargolargolargolargolargolargolargolargolar_suffix text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'largolargolargolargolargolargolargolargolargolargolargolargolar', '_suffix', 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
CREATE TABLE test (name text);
|
||||||
|
-- Test unique identifier creation with normal length UTF8 colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'piraña', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with normal length UTF8 colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'piraña', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with normal length UTF8 colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'piraña', '_suffix', 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with long length UTF8 colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL, 'test'::regclass);
|
||||||
|
|
||||||
|
-- Test unique identifier creation with prefix with long length UTF8 colname
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL, 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE test (prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier('prefix_', 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', NULL, 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test unique identifier creation with suffix with long length UTF8 colname
|
||||||
|
CREATE TABLE test (name text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix', 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test new identifier is found when name is taken from previous case
|
||||||
|
CREATE TABLE test (piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix text);
|
||||||
|
SELECT * FROM cartodb._CDB_Unique_Column_Identifier(NULL, 'piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácidpin', '_suffix', 'test'::regclass);
|
||||||
|
DROP TABLE test;
|
||||||
|
|
||||||
|
-- Test _CDB_Octet_Truncate simple case
|
||||||
|
SELECT * FROM cartodb._CDB_Octet_Truncate('piraña', 5);
|
||||||
|
|
||||||
|
-- Test _CDB_Octet_Truncate UTF8 case
|
||||||
|
SELECT * FROM cartodb._CDB_Octet_Truncate('piraña', 6);
|
||||||
|
|
||||||
|
-- Test _CDB_Octet_Truncate UTF8 case
|
||||||
|
SELECT * FROM cartodb._CDB_Octet_Truncate('piraña', 7);
|
59
test/CDB_HelperTest_expect
Normal file
59
test/CDB_HelperTest_expect
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
relname
|
||||||
|
prefix_relname
|
||||||
|
relname_suffix
|
||||||
|
largolargolargolargolargolargolargolargolargolargolargolargo
|
||||||
|
prefix_largolargolargolargolargolargolargolargolargolargolar
|
||||||
|
CREATE TABLE
|
||||||
|
prefix_largolargolargolargolargolargolargolargolargolargolar_0
|
||||||
|
DROP TABLE
|
||||||
|
largolargolargolargolargolargolargolargolargolargolar_suffix
|
||||||
|
CREATE TABLE
|
||||||
|
largolargolargolargolargolargolargolargolargolargolar_suffix_0
|
||||||
|
DROP TABLE
|
||||||
|
piraña
|
||||||
|
prefix_piraña
|
||||||
|
piraña_suffix
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácid
|
||||||
|
prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi
|
||||||
|
CREATE TABLE
|
||||||
|
prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_0
|
||||||
|
DROP TABLE
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix
|
||||||
|
CREATE TABLE
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix_0
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
colname
|
||||||
|
prefix_colname
|
||||||
|
colname_suffix
|
||||||
|
largolargolargolargolargolargolargolargolargolargolargolargo
|
||||||
|
prefix_largolargolargolargolargolargolargolargolargolargolar
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
prefix_largolargolargolargolargolargolargolargolargolargolar_0
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
largolargolargolargolargolargolargolargolargolargolar_suffix
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
largolargolargolargolargolargolargolargolargolargolar_suffix_0
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
piraña
|
||||||
|
prefix_piraña
|
||||||
|
piraña_suffix
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpiñaácid
|
||||||
|
prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
prefix_piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_0
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix
|
||||||
|
DROP TABLE
|
||||||
|
CREATE TABLE
|
||||||
|
piñaácidpiñaácidpiñaácidpiñaácidpiñaácidpi_suffix_0
|
||||||
|
DROP TABLE
|
||||||
|
pira
|
||||||
|
pirañ
|
||||||
|
piraña
|
Loading…
Reference in New Issue
Block a user