0

I'm facing a quote problem on a pgrouting query.

What I'm thinking is wrong is that my query only works if I use one, then four, then eight quotes on encapsulated queries.

Is there a way to simplify this ?

SELECT *
FROM pgr_pointsaspolygon(
'SELECT id::int4, st_x(ways_vertices_pgr.the_geom) as x, st_y(ways_vertices_pgr.the_geom) as y 
  FROM pgr_drivingDistance(
    ''''SELECT gid as id, source, target, ST_Length_Spheroid(the_geom, ''''''''SPHEROID["WGS 84",6378137,298.257223563]'''''''') as cost FROM ways'''', 
    7, 
    550, 
    false, 
    false)
INNER JOIN ways_vertices_pgr on (ways_vertices_pgr.id = id2)');

Thanks in advance

1

It's not a pg_routing problem - in postres if you have to place single quote mark inside of single quoted string you have to double it so parser knows which mark is inside and which is ending the quote. Following the documentation:

4.1.2.1. String Constants A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'. To include a single-quote character within a string constant, write two adjacent single quotes, e.g., 'Dianne''s horse'. Note that this is not the same as a double-quote character (").

So this could work too:

SELECT *
FROM pgr_pointsaspolygon(
'SELECT id::int4, st_x(ways_vertices_pgr.the_geom) as x, st_y(ways_vertices_pgr.the_geom) as y 
  FROM pgr_drivingDistance(
    ''SELECT gid as id, source, target, ST_Length_Spheroid(the_geom, ''SPHEROID["WGS 84",6378137,298.257223563]'') as cost FROM ways'', 
    7, 
    550, 
    false, 
    false)
INNER JOIN ways_vertices_pgr on (ways_vertices_pgr.id = id2)');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.