[pgrouting-users] ultimate solution to assign_vertex_id() bug :-)

Description:
CREATE TABLE will create implicit sequence "vertices_tmp_id_seq" for serial column "vertices_tmp.id" CONTEXT: SQL statement "CREATE TABLE vertices_tmp (id serial)" PL/pgSQL function "assign_vertex_id" line 21 at EXECUTE statement ERROR: relation "baharestan.roads" does not exist CONTEXT: SQL statement "SELECT count(*) as countids FROM "baharestan.roads"" PL/pgSQL function "assign_vertex_id" line 28 at FOR over EXECUTE statement

sorry for my poor english:

I read plpgsql program of assign_vertex_id in pgAdminIII and find a bug,there are three lines like followed:
...
FOR _r IN EXECUTE 'SELECT srid FROM geometry_columns WHERE f_table_name='''|| quote_ident(geom_table)||''';' LOOP
srid := _r.srid;
    END LOOP;
...

there is something wrong with "quote_ident(tablename)",this command will add " around tablename, just like quote_ident(tablename) <=> "tablename"
However, the above condition, program should modified to:
...
FOR _r IN EXECUTE 'SELECT srid FROM geometry_columns WHERE f_table_name='''|| geom_table||''';' LOOP
srid := _r.srid;
    END LOOP;
...

that's because there are ' around tablename, there will be error with '"tablename"' instead of 'tablename'.

ok! with above the little modification, there will be no error with assign_vertex_id() :slight_smile:

YuLongzhen
266061 Qingdao, China.
realylz@126.com

YuLongzhen,

Thank you for your report. I think your analysis and solution are correct.

Daniel or Anton,

quote_ident() should only be used when quoting a column or table when it is actually being used as a column or table object in the SQL and not when it is being used as a string. But you guys know that and I assume this is just a brain slip when editing the script. Anyway, please update git when you have a chance.

Thanks,
   -Steve

On 10/4/2011 7:26 PM, realylz wrote:

      Description:

CREATE TABLE will create implicit sequence "vertices_tmp_id_seq" for
serial column "vertices_tmp.id" CONTEXT: SQL statement "CREATE TABLE
vertices_tmp (id serial)" PL/pgSQL function "assign_vertex_id" line 21
at EXECUTE statement ERROR: relation "baharestan.roads" does not exist
CONTEXT: SQL statement "SELECT count(*) as countids FROM
"baharestan.roads"" PL/pgSQL function "assign_vertex_id" line 28 at FOR
over EXECUTE statement

sorry for my poor english:

I read plpgsql program of assign_vertex_id in pgAdminIII and find a
bug,there are three lines like followed:

*... *

*FOR _r IN EXECUTE 'SELECT srid FROM geometry_columns WHERE
f_table_name='''|| quote_ident(geom_table)||''';' LOOP
srid := _r.srid;
END LOOP; *

*... *

there is something wrong with "quote_ident(tablename)",this command
will add " around tablename, just like *quote_ident(tablename) <=>
"tablename" *
However, the above condition, program should modified to:

*... *

*FOR _r IN EXECUTE 'SELECT srid FROM geometry_columns WHERE
f_table_name='''|| geom_table||''';' LOOP
srid := _r.srid;
END LOOP; *

*... *

that's because there are ' around tablename, there will be error with
'"tablename"' instead of 'tablename'.
ok! with above the little modification, there will be no error with
assign_vertex_id() :slight_smile:
YuLongzhen
266061 Qingdao, China.
realylz@126.com <mailto:realylz@126.com>

_______________________________________________
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users

On Wed, Oct 5, 2011 at 12:07 PM, Stephen Woodbridge <woodbri@swoodbridge.com> wrote:

YuLongzhen,

Thank you for your report. I think your analysis and solution are correct.

Daniel or Anton,

quote_ident() should only be used when quoting a column or table when it is actually being used as a column or table object in the SQL and not when it is being used as a string. But you guys know that and I assume this is just a brain slip when editing the script. Anyway, please update git when you have a chance.

Thanks,
-Steve

Hi YuLongzhen and Steve,

As far as I remember assign_vertex_id has almost not been modified since it was part of pgDijkstra many years ago.
So thank you for looking into this, YuLongzhen! Nobody has ever notified this (and reported).

YuLongzhen, if you want to clone the Github repository, make the modifications and submit a “pull request”, then the credits for the patch will be yours.

Daniel


Georepublic UG & Georepublic Japan
eMail: daniel.kastl@georepublic.de
Web: http://georepublic.de

On Wed, Oct 5, 2011 at 12:22 PM, Daniel Kastl <daniel@georepublic.de> wrote:

On Wed, Oct 5, 2011 at 12:07 PM, Stephen Woodbridge <woodbri@swoodbridge.com> wrote:

YuLongzhen,

Thank you for your report. I think your analysis and solution are correct.

Daniel or Anton,

quote_ident() should only be used when quoting a column or table when it is actually being used as a column or table object in the SQL and not when it is being used as a string. But you guys know that and I assume this is just a brain slip when editing the script. Anyway, please update git when you have a chance.

Thanks,
-Steve

Hi YuLongzhen and Steve,

As far as I remember assign_vertex_id has almost not been modified since it was part of pgDijkstra many years ago.
So thank you for looking into this, YuLongzhen! Nobody has ever notified this (and reported).

YuLongzhen, if you want to clone the Github repository, make the modifications and submit a “pull request”, then the credits for the patch will be yours.

Daniel

Or quote_literal() might be even better:
http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html#PLPGSQL-QUOTE-LITERAL-EXAMPLE


FOR _r IN EXECUTE ‘SELECT srid FROM geometry_columns WHERE f_table_name=’|| quote_literal(geom_table)||‘;’ LOOP
srid := _r.srid;
END LOOP;

Or am I wrong?
I have never really taken note much at these string functions, though there seem to be many useful ones:
http://www.postgresql.org/docs/8.4/static/functions-string.html

Daniel


Georepublic UG & Georepublic Japan
eMail: daniel.kastl@georepublic.de
Web: http://georepublic.de