     FROM pg_class c 
     JOIN pg_attribute a ON a.attrelid = c.oid 
     JOIN pg_type t ON a.atttypid = t.oid,
-    (VALUES (geom_name, 4326), (mercgeom_name, 3857) ) as f(desired_attname, desired_srid)
+    (VALUES (const.geomcol, 4326), (const.mercgeomcol, 3857) ) as f(desired_attname, desired_srid)
     WHERE c.oid = reloid
     AND a.attnum > 0
     AND NOT a.attisdropped

RETURNS void 
AS $$
DECLARE
  -- Because we're going to change these some day, ha ha ha ha!
  geom_name TEXT := 'the_geom';
  mercgeom_name TEXT := 'the_geom_webmercator';
  primary_key_name TEXT := 'cartodb_id';
  
  relname TEXT;
  relschema TEXT;

  JOIN pg_class ci ON i.indexrelid = ci.oid
  WHERE c.oid = reloid 
  AND NOT a.attisdropped
  AND a.attname != const.pkey
  AND i.indisprimary;

  -- Yes? Then drop it, we're adding our own PK to the column
  -- we prefer.
  IF FOUND THEN
    RAISE DEBUG 'CDB(_CDB_Add_Indexes): dropping unwanted primary key ''%''', rec.pkey;
    sql := Format('ALTER TABLE %s DROP CONSTRAINT IF EXISTS %s', reloid::text, rec.pkey);
    PERFORM _CDB_SQL(sql, '_CDB_Add_Indexes');
  END IF;


