0

I am new in sql and i am trying to get that works a subquery with pgr_drivingdistance and pgr_pointsaspolygon but i get the next error:

subqueries in FROM must to have an alias,for example, FROM (SELECT ...) [AS] foo.But in the code below the alias is di

Here is the code:

SELECT 1 as result,* FROM  pgr_pointsaspolygon('SELECT id, ST_X(the_geom) AS x, ST_Y(the_geom) AS y FROM ( 
     SELECT id,seq, id1 AS node, id2 AS edge, cost, the_geom FROM pgr_drivingdistance(
       ''''SELECT id, source, target, time_4 as cost FROM jaen'''',
          1, 15, false, false
      )as di
      JOIN jaen_vertices_pgr pt
      ON di.id1 = pt.id)');
  • 1
    Isn't the problem that pgr_pointsapolyon returns a geometry, so you can't join it on id as you are? You should be able to run something like:, SELECT * FROM pgr_pointsaspolygon('SELECT id, ST_X(the_geom) AS x, ST_Y(the_geom) AS y FROM ( SELECT id, seq, id1 AS node, id2 AS edge, cost, the_geom FROM pgr_drivingdistance( ''''SELECT id, source, target, time_4 as cost FROM jaen'''', 1, 15, false, false ) as dd ) as di ) as pp; – John Powell Feb 2 '15 at 17:49
  • Hello. Thanks for your comment. When i try to run it i get this error 'ERROR: una cadena de caracteres entre comillas está inconclusa en o cerca de «'SELECT id, ST_X(the_geom) AS x, ST_Y(the_geom) AS y FROM ( SELECT id, seq, id1 AS node, id2 AS edge, cost, the_geom FROM pgr_drivingdistance( ''''SELECT id, source, target, time_4 as cost FROM jaen'''', 1, 15, false, false ) as dd ) as di ) as pp;» LINE 1: SELECT * FROM pgr_pointsaspolygon('SELECT id, ST_X(the_geom)...'.I tested closing the first SELECT into as pp but i get another error. Perhaps insert a braket at the end?. – user19566 Feb 3 '15 at 11:05
  • I think you only need one set of '' around your query that is passed to pgr_drivingdistance? – John Powell Feb 3 '15 at 11:11
  • I tried this to but about two days ago i found a theme related to [postgresql.org/message-id/52484C84.3000504@gmail.com]; adding four ' into pgr_drivingdistance SQL it works. I will try to change the SQL parameters. – user19566 Feb 3 '15 at 12:16
  • Perhaps to get the correct result i should add something like ` JOIN jaen_vertices_pgr pt ON di.id1 = pt.id;` but using dd,di,pp – user19566 Feb 3 '15 at 12:22

Your Answer

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

Browse other questions tagged or ask your own question.