From ea9503bd32ddb8d78bcf4e8fa0ed2da02cb022b1 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 20 Nov 2015 12:24:46 +0100 Subject: [PATCH 1/3] Allow dots in column names to be cartodbfied This fixes #6144 of cartodb --- test/CDB_CartodbfyTableTest.sql | 9 +++++++++ test/CDB_CartodbfyTableTest_expect | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/test/CDB_CartodbfyTableTest.sql b/test/CDB_CartodbfyTableTest.sql index fc6bd8a..0464cea 100644 --- a/test/CDB_CartodbfyTableTest.sql +++ b/test/CDB_CartodbfyTableTest.sql @@ -319,6 +319,15 @@ SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_i SELECT cartodb_id, cartodb_id_0 from test; DROP TABLE test; +CREATE TABLE test ( + name varchar, + "first.value" integer, + "second.value" integer +); +INSERT INTO test VALUES ('one', 1, 2), ('two', 3, 4); +SELECT CDB_CartodbfyTableCheck('test', 'Table with dots in name columns (cartodb #6114)'); +SELECT name, "first.value" from test; +DROP TABLE test; -- TODO: table with existing custom-triggered the_geom diff --git a/test/CDB_CartodbfyTableTest_expect b/test/CDB_CartodbfyTableTest_expect index 6103dc8..30da686 100644 --- a/test/CDB_CartodbfyTableTest_expect +++ b/test/CDB_CartodbfyTableTest_expect @@ -102,5 +102,11 @@ Table with non unique and null cartodb_id #148 cartodbfied fine 3| 4|2 DROP TABLE +CREATE TABLE +INSERT 0 2 +Table with dots in name columns (cartodb #6114) cartodbfied fine +one|1 +two|3 +DROP TABLE DROP FUNCTION DROP FUNCTION From a0ca2288f41213cc2178b9e7b63e4208bbbc6221 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 20 Nov 2015 12:56:52 +0100 Subject: [PATCH 2/3] Fix: Cartodbfication failed with existing PK This fixes #174 When a unique index and a primary key contraint existed for a column named cartodb_id cartodbfy tried to add another PK constraint --- scripts-available/CDB_CartodbfyTable.sql | 2 +- test/CDB_CartodbfyTableTest.sql | 14 ++++++++++++++ test/CDB_CartodbfyTableTest_expect | 10 ++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts-available/CDB_CartodbfyTable.sql b/scripts-available/CDB_CartodbfyTable.sql index 849238e..687802a 100644 --- a/scripts-available/CDB_CartodbfyTable.sql +++ b/scripts-available/CDB_CartodbfyTable.sql @@ -504,7 +504,7 @@ BEGIN IF rec.atttypid IN (20,21,23) THEN -- And it's a unique primary key! Done! - IF rec.indisprimary AND rec.indisunique AND rec.attnotnull THEN + IF (rec.indisprimary OR rec.indisunique) AND rec.attnotnull THEN RAISE DEBUG 'CDB(_CDB_Has_Usable_Primary_ID): %', Format('found good ''%s''', const.pkey); RETURN true; diff --git a/test/CDB_CartodbfyTableTest.sql b/test/CDB_CartodbfyTableTest.sql index 0464cea..a5f7593 100644 --- a/test/CDB_CartodbfyTableTest.sql +++ b/test/CDB_CartodbfyTableTest.sql @@ -319,6 +319,20 @@ SELECT CDB_CartodbfyTableCheck('test', 'Table with non unique and null cartodb_i SELECT cartodb_id, cartodb_id_0 from test; DROP TABLE test; +CREATE TABLE test ( + cartodb_id integer +); +CREATE UNIQUE INDEX "test_cartodb_id_key" ON test (cartodb_id); +CREATE UNIQUE INDEX "test_cartodb_id_pkey" ON test (cartodb_id); +ALTER TABLE test ADD CONSTRAINT "test_pkey" PRIMARY KEY USING INDEX test_cartodb_id_pkey; +INSERT INTO test VALUES + (1), + (2), + (3); +SELECT CDB_CartodbfyTableCheck('test', 'Table with primary key and unique index on it #174'); +SELECT cartodb_id from test; +DROP TABLE test; + CREATE TABLE test ( name varchar, "first.value" integer, diff --git a/test/CDB_CartodbfyTableTest_expect b/test/CDB_CartodbfyTableTest_expect index 30da686..cfb3e3b 100644 --- a/test/CDB_CartodbfyTableTest_expect +++ b/test/CDB_CartodbfyTableTest_expect @@ -103,6 +103,16 @@ Table with non unique and null cartodb_id #148 cartodbfied fine 4|2 DROP TABLE CREATE TABLE +CREATE INDEX +CREATE INDEX +ALTER TABLE +INSERT 0 3 +Table with primary key and unique index on it #174 cartodbfied fine +1 +2 +3 +DROP TABLE +CREATE TABLE INSERT 0 2 Table with dots in name columns (cartodb #6114) cartodbfied fine one|1 From 83ac8f450275d6040a22aff9a6a80e5ade50c4d8 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 20 Nov 2015 13:05:15 +0100 Subject: [PATCH 3/3] Fix: Allow dots in column names to be cartodbfied This fixes #6144 of cartodb Note that prior commit ea9503bd32ddb8d78bcf4e8fa0ed2da02cb022b1 only added the tests for this, but not the actual fix (oops) --- scripts-available/CDB_CartodbfyTable.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts-available/CDB_CartodbfyTable.sql b/scripts-available/CDB_CartodbfyTable.sql index 687802a..ceee0cc 100644 --- a/scripts-available/CDB_CartodbfyTable.sql +++ b/scripts-available/CDB_CartodbfyTable.sql @@ -1068,8 +1068,8 @@ BEGIN -- Add now add all the rest of the columns -- by selecting their names into an array and -- joining the array with a comma - SELECT - ',' || array_to_string(array_agg(a.attname),',') AS column_name_sql, + SELECT + ',' || array_to_string(array_agg(Format('%I',a.attname)),',') AS column_name_sql, Count(*) AS count INTO rec FROM pg_class c