pgRouting / pgrouting

Repository contains pgRouting library. Development branch is "develop", stable branch is "master"
https://pgrouting.org
GNU General Public License v2.0
1.17k stars 369 forks source link

pgr_CreateTopology NOTICE: Unexpected error column "cname" does not exist after renaming an old table #900

Closed robe2 closed 7 years ago

robe2 commented 7 years ago

Expected behavior and actual behavior

If you run create topology and had an old table that has the same index names, you get error

` NOTICE: Unexpected error column "cname" does not exist

`

I think the problem is createtopology is not checking if an index name is already in use, and blindly creates indexes it sees missing.

Index names have to be unique within a schema. Though though logic might just be an error in its checking of names when it's inspecting the catalog

e.g. if idx_mbta_lines_source exists as an index, and it decide new table should have an index with that name

Steps to reproduce the problem

  1. SELECT pgr_CreateTopology('mbta_lines', 1, 'geom', 'id', clean:true)
  2. ALTER TABLE mbta_lines RENAME TO mbta_arc;
  3. CREATE TABLE mbta_lines AS SELECT * FROM mbta_arc;; 4) SELECT pgr_CreateTopology('mbta_lines', 1, 'geom', 'id', clean:true);

Specifications like the version of pgRouting/PostGIS and PostgreSQL as well as Operating System

Use the commands:

SELECT version();
SELECT postgis_full_version();
SELECT pgr_version();
 SELECT version();
                           version
-------------------------------------------------------------
 PostgreSQL 9.6.3, compiled by Visual C++ build 1800, 64-bit
(1 row)

Time: 0.883 ms
 SELECT postgis_full_version();
                                                                        postgis_full_version
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="2.3.3 r15473" GEOS="3.6.1-CAPI-1.10.1 r4317" PROJ="Rel. 4.9.1, 04 March 2015" GDAL="GDAL 2.2.1, released 2017/06/23" LIBXML="2.7.8" LIBJSON="0.12" RASTER
(1 row)

Time: 128.291 ms
SELECT pgr_version();
              pgr_version
----------------------------------------
 (2.4.1,v2.4.1,722e04e03,master,1.59.0)
(1 row)
cvvergara commented 7 years ago

@robe2 Trying to reproduce the problem with this code:

SELECT pgr_CreateTopology('edge_table', 0.001, 'the_geom', 'id', clean:true);
ALTER TABLE edge_table RENAME TO mbta_arc;
CREATE TABLE edge_table AS SELECT * FROM mbta_arc;;
SELECT pgr_CreateTopology('edge_table', 0.001, 'the_geom', 'id', clean:true);