From e3bba2ee4bf6f794b25b6b2dafa768109e7cdae9 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Mon, 14 Sep 2015 16:48:57 +0200 Subject: [PATCH] Fix `the_geom` already exists error #141 --- scripts-available/CDB_CartodbfyTable.sql | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts-available/CDB_CartodbfyTable.sql b/scripts-available/CDB_CartodbfyTable.sql index 71c7cad..dbea59a 100644 --- a/scripts-available/CDB_CartodbfyTable.sql +++ b/scripts-available/CDB_CartodbfyTable.sql @@ -826,8 +826,10 @@ BEGIN END LOOP; -- If geom is the wrong name, just rename it. - IF has_geom AND has_geom_name != const.geomcol THEN - sql := Format('ALTER TABLE %s RENAME COLUMN %s TO %s', reloid::text, has_geom_name, const.geomcol); + IF has_geom AND has_geom_name != const.geomcol THEN + sql := Format('ALTER TABLE %I DROP COLUMN IF EXISTS %I', reloid::text, const.geomcol); + PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom'); + sql := Format('ALTER TABLE %I RENAME COLUMN %I TO %I', reloid::text, has_geom_name, const.geomcol); PERFORM _CDB_SQL(sql,'_CDB_Has_Usable_Geom'); END IF;