1

I tried many times to create new layer from query result, but i got this error message, when loading it.

" PostgreSQL layer has no primary key."

    SELECT * FROM pgr_drivingDistance('select gid::int4 as id, source, target,
length_m as cost from public.ospr_ways', 24710, 1000
) AS routed1
INNER JOIN ospr_ways AS e
ON routed1.edge = e.gid::int4;

update: i have installed QGIS 3.10.5 LTR 64x, PostgreSQL 12 64x, PostGIS 3.0 for PostgreSQL 64X, Windows 10 64x i already created postgis, pgrouting extension from pgAdmin for target database, and the query successfully executed and displayed it from pgAdmin, but i can't load my query as a new layer from db manager of QGIS.

8
  • Could you add the complete version details of QGIS, PostGIS and pgRouting?
    – geozelot
    May 14 '20 at 15:22
  • ok, i updated the question, please check it
    – GIS Man
    May 14 '20 at 15:31
  • Well, which field is supposed to be the primary key? Is that set?
    – Stella
    May 14 '20 at 17:14
  • Maybe try something like "ADD PRIMARY KEY (osm_id);"
    – Stella
    May 14 '20 at 17:17
  • Check Colum(s) with unique values and set to seq, or add ROW_NUMBER() OVER() AS id to the SELECT?
    – geozelot
    May 14 '20 at 17:27
2

New Layer added from query result successfully, after defining fields for query layer.

SELECT seq AS id, node as id1, edge AS id2, the_geom
FROM pgr_drivingDistance('select gid as id, source, target, cost_s
as cost from ways', 24710, 300) AS cadis 
JOIN ways AS e ON cadis.edge = e.gid;

Thank you @geozelot

0

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.