diff --git a/scripts-available/CDB_CartodbfyTable.sql b/scripts-available/CDB_CartodbfyTable.sql index d6fba32..f5d795c 100644 --- a/scripts-available/CDB_CartodbfyTable.sql +++ b/scripts-available/CDB_CartodbfyTable.sql @@ -527,7 +527,7 @@ BEGIN useable_key := false; -- Other fatal error WHEN others THEN - PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: %s', SQLERRM)); + PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: not valid %s', SQLERRM)); END; -- Clean up test constraint @@ -538,13 +538,9 @@ BEGIN ELSE RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', - Format('found non-unique ''%s'', renaming it', const.pkey); + Format('found non-unique ''%s''', const.pkey); - PERFORM _CDB_SQL( - Format('ALTER TABLE %s RENAME COLUMN %s TO %I', - reloid::text, rec.attname, - cartodb._CDB_Unique_Column_Identifier(NULL, const.pkey, NULL, reloid)), - '_CDB_Has_Usable_Primary_ID'); + PERFORM _CDB_Error(sql, Format('_CDB_Has_Usable_Primary_ID: non-unique %s', const.pkey)); END IF; diff --git a/test/CDB_CartodbfyTableTest.sql b/test/CDB_CartodbfyTableTest.sql index 2144d0b..d32f1e8 100644 --- a/test/CDB_CartodbfyTableTest.sql +++ b/test/CDB_CartodbfyTableTest.sql @@ -178,7 +178,7 @@ DROP TABLE t; -- table with empty cartodb_id field of type text CREATE TABLE t AS SELECT null::text as cartodb_id; SELECT CDB_CartodbfyTableCheck('t', 'empty text cartodb_id'); -select cartodb_id,cartodb_id_0 FROM t; +SELECT cartodb_id from t; DROP TABLE t; -- table with existing cartodb_id field of type int4 not sequenced @@ -294,7 +294,7 @@ INSERT INTO test VALUES (NULL), (3); SELECT CDB_CartodbfyTableCheck('test', 'Table with null cartodb_id #148'); -SELECT cartodb_id, cartodb_id_0 from test; +SELECT cartodb_id from test; DROP TABLE test; -- Table with non unique cartodb_id @@ -306,7 +306,7 @@ INSERT INTO test VALUES (2), (2); SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique cartodb_id #148'); -SELECT cartodb_id, cartodb_id_0 from test; +SELECT cartodb_id from test; DROP TABLE test; -- Table with non unique and null cartodb_id @@ -319,7 +319,7 @@ INSERT INTO test VALUES (NULL), (2); SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_id #148'); -SELECT cartodb_id, cartodb_id_0 from test; +SELECT cartodb_id from test; DROP TABLE test; CREATE TABLE test ( diff --git a/test/CDB_CartodbfyTableTest_expect b/test/CDB_CartodbfyTableTest_expect index aeadfa1..b97e9d6 100644 --- a/test/CDB_CartodbfyTableTest_expect +++ b/test/CDB_CartodbfyTableTest_expect @@ -33,8 +33,8 @@ SELECT 1 ERROR: CDB(_CDB_Rewrite_Table:22P02:invalid input syntax for integer: "nan"): CREATE TABLE public.t_0 AS SELECT cartodb_id::bigint ,NULL::geometry(Geometry,4326) AS the_geom,NULL::geometry(Geometry,3857) AS the_geom_webmercator FROM t DROP TABLE SELECT 1 -empty text cartodb_id cartodbfied fine -1| +ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE t ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) + DROP TABLE SELECT 1 unsequenced cartodb_id cartodbfied fine @@ -86,30 +86,30 @@ Table with both the_geom and wkb_geometry #141 cartodbfied fine DROP TABLE CREATE TABLE INSERT 0 1 -ERROR: CDB(_CDB_Has_Usable_Primary_ID: multiple primary keys for table "many_colliding_columns" are not allowed): ALTER TABLE many_colliding_columns ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) +ERROR: CDB(_CDB_Has_Usable_Primary_ID: not valid multiple primary keys for table "many_colliding_columns" are not allowed): ALTER TABLE many_colliding_columns ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) DROP TABLE CREATE TABLE INSERT 0 4 -Table with null cartodb_id #148 cartodbfied fine -1|1 -2|2 -3| -4|3 +ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) +1 +2 + +3 DROP TABLE CREATE TABLE INSERT 0 3 -Table with non unique cartodb_id #148 cartodbfied fine -1|1 -2|2 -3|2 +ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) +1 +2 +2 DROP TABLE CREATE TABLE INSERT 0 4 -Table with non unique and null cartodb_id #148 cartodbfied fine -1|1 -2|2 -3| -4|2 +ERROR: CDB(_CDB_Has_Usable_Primary_ID: non-unique cartodb_id): ALTER TABLE test ADD CONSTRAINT cartodb_id_pk PRIMARY KEY (cartodb_id) +1 +2 + +2 DROP TABLE CREATE TABLE CREATE INDEX