       -- If it's the right SRID, we can use it in place without
       -- transforming it!
       IF r1.srid = r1.desired_srid OR _CDB_Geometry_SRID(reloid, r1.attname) = r1.desired_srid THEN
-        RAISE DEBUG '_CDB_Has_Usable_Geom found acceptable ''%''', r1.attname;
-
-        -- If it's the wrong name, just rename it.
-        IF r1.attname != r1.desired_attname THEN
-          EXECUTE Format('ALTER TABLE %s RENAME COLUMN %s TO %s', reloid::text, r1.attname, r1.desired_attname);
-          RAISE DEBUG '_CDB_Has_Usable_Geom renamed % to %', r1.attname, r1.desired_attname;
-        END IF;
-
-        IF r1.desired_attname = geom_name THEN
-          has_geom = true;
-        ELSIF r1.desired_attname = mercgeom_name THEN
-          has_mercgeom = true;
+
+        RAISE DEBUG 'CDB(_CDB_Has_Usable_Geom): %', Format('found acceptable ''%s''', r1.attname);
+
+        IF r1.desired_attname = const.geomcol THEN
+          has_geom := true;
+          has_geom_name := r1.attname;
+        ELSIF r1.desired_attname = const.mercgeomcol THEN
+          has_mercgeom := true;
+          has_mercgeom_name := r1.attname;
         END IF;
         
       END IF;

  rec RECORD;
BEGIN

  RAISE DEBUG '_CDB_Geometry_SRID, entered';
  
  EXECUTE Format('SELECT ST_SRID(%s) AS srid FROM %s LIMIT 1', columnname, reloid::text)
  INTO rec;

  IF FOUND THEN 
    RETURN rec.srid;
  ELSE
    RETURN 0;
  END IF;
  
END;
$$ LANGUAGE 'plpgsql';

  JOIN pg_class ci ON ci.oid = i.indexrelid
  WHERE attnum > 0 
  AND c.oid = reloid
  AND a.attname = const.pkey
  AND i.indisprimary
  AND i.indisunique
  AND NOT attisdropped;
  
  -- No primary key? Add one.
  IF NOT FOUND THEN
    sql := Format('ALTER TABLE %s ADD PRIMARY KEY (%s)', reloid::text, const.pkey);
    PERFORM _CDB_SQL(sql, '_CDB_Add_Indexes');
  END IF;
  
  -- Add geometry indexes to all "special geometry columns" that 
