@@ -67,6 +67,8 @@ NOTICE: trigger "update_updated_at_trigger" for table "c.t4" does not exist, sk
|
|||||||
NOTICE: trigger "test_quota" for table "c.t4" does not exist, skipping
|
NOTICE: trigger "test_quota" for table "c.t4" does not exist, skipping
|
||||||
NOTICE: trigger "test_quota_per_row" for table "c.t4" does not exist, skipping
|
NOTICE: trigger "test_quota_per_row" for table "c.t4" does not exist, skipping
|
||||||
NOTICE: Column cartodb_id already exists
|
NOTICE: Column cartodb_id already exists
|
||||||
|
NOTICE: Existing cartodb_id field does not have an associated sequence, renaming
|
||||||
|
NOTICE: Trying to recover data from _cartodb_id0 coumn
|
||||||
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
NOTICE: event trigger "cdb_on_relation_create" does not exist, skipping
|
||||||
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
NOTICE: event trigger "cdb_on_relation_drop" does not exist, skipping
|
||||||
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
NOTICE: event trigger "cdb_on_alter_column" does not exist, skipping
|
||||||
|
|||||||
@@ -89,13 +89,21 @@ BEGIN
|
|||||||
|
|
||||||
IF had_column THEN
|
IF had_column THEN
|
||||||
|
|
||||||
|
SELECT pg_catalog.pg_get_serial_sequence(reloid::text, 'cartodb_id')
|
||||||
|
AS seq INTO rec2;
|
||||||
|
|
||||||
-- Check data type is an integer
|
-- Check data type is an integer
|
||||||
SELECT t.typname, t.oid, a.attnotnull FROM pg_type t, pg_attribute a
|
SELECT
|
||||||
|
pg_catalog.pg_get_serial_sequence(reloid::text, 'cartodb_id') as seq,
|
||||||
|
t.typname, t.oid, a.attnotnull FROM pg_type t, pg_attribute a
|
||||||
WHERE a.atttypid = t.oid AND a.attrelid = reloid AND NOT a.attisdropped
|
WHERE a.atttypid = t.oid AND a.attrelid = reloid AND NOT a.attisdropped
|
||||||
AND a.attname = 'cartodb_id'
|
AND a.attname = 'cartodb_id'
|
||||||
INTO STRICT rec;
|
INTO STRICT rec;
|
||||||
IF rec.oid NOT IN (20,21,23) THEN -- int2, int4, int8 {
|
-- 20=int2, 21=int4, 23=int8
|
||||||
|
IF rec.oid NOT IN (20,21,23) THEN
|
||||||
RAISE NOTICE 'Existing cartodb_id field is of invalid type % (need int2, int4 or int8), renaming', rec.typname;
|
RAISE NOTICE 'Existing cartodb_id field is of invalid type % (need int2, int4 or int8), renaming', rec.typname;
|
||||||
|
ELSIF rec.seq IS NULL THEN
|
||||||
|
RAISE NOTICE 'Existing cartodb_id field does not have an associated sequence, renaming';
|
||||||
ELSE -- }{
|
ELSE -- }{
|
||||||
sql := 'ALTER TABLE ' || reloid::text || ' ALTER COLUMN cartodb_id SET NOT NULL';
|
sql := 'ALTER TABLE ' || reloid::text || ' ALTER COLUMN cartodb_id SET NOT NULL';
|
||||||
IF NOT EXISTS ( SELECT c.conname FROM pg_constraint c, pg_attribute a
|
IF NOT EXISTS ( SELECT c.conname FROM pg_constraint c, pg_attribute a
|
||||||
|
|||||||
@@ -182,18 +182,24 @@ SELECT CDB_CartodbfyTableCheck('t', 'cartodbfied with view');
|
|||||||
DROP VIEW v;
|
DROP VIEW v;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
-- table with existing cartodb_id field ot type text
|
-- table with existing cartodb_id field of type text
|
||||||
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
CREATE TABLE t AS SELECT 10::text as cartodb_id;
|
||||||
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
SELECT CDB_CartodbfyTableCheck('t', 'text cartodb_id');
|
||||||
select cartodb_id/2 FROM t;
|
select cartodb_id/2 FROM t;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
-- table with existing cartodb_id field ot type text not casting
|
-- table with existing cartodb_id field of type text not casting
|
||||||
CREATE TABLE t AS SELECT 'nan' as cartodb_id;
|
CREATE TABLE t AS SELECT 'nan' as cartodb_id;
|
||||||
SELECT CDB_CartodbfyTableCheck('t', 'uncasting text cartodb_id');
|
SELECT CDB_CartodbfyTableCheck('t', 'uncasting text cartodb_id');
|
||||||
select cartodb_id,_cartodb_id0 FROM t;
|
select cartodb_id,_cartodb_id0 FROM t;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
|
|
||||||
|
-- table with existing cartodb_id field of type int4 not sequenced
|
||||||
|
CREATE TABLE t AS SELECT 1::int4 as cartodb_id;
|
||||||
|
SELECT CDB_CartodbfyTableCheck('t', 'unsequenced cartodb_id');
|
||||||
|
select cartodb_id FROM t;
|
||||||
|
DROP TABLE t;
|
||||||
|
|
||||||
-- TODO: table with existing custom-triggered the_geom
|
-- TODO: table with existing custom-triggered the_geom
|
||||||
|
|
||||||
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
|
DROP FUNCTION CDB_CartodbfyTableCheck(regclass, text);
|
||||||
|
|||||||
@@ -40,5 +40,9 @@ SELECT 1
|
|||||||
uncasting text cartodb_id cartodbfied fine
|
uncasting text cartodb_id cartodbfied fine
|
||||||
1|nan
|
1|nan
|
||||||
DROP TABLE
|
DROP TABLE
|
||||||
|
SELECT 1
|
||||||
|
unsequenced cartodb_id cartodbfied fine
|
||||||
|
1
|
||||||
|
DROP TABLE
|
||||||
DROP FUNCTION
|
DROP FUNCTION
|
||||||
DROP FUNCTION
|
DROP FUNCTION
|
||||||
|
|||||||
Reference in New Issue
Block a user