我做 pgRouting 并且我需要将整数结果从我的SELECT
.
SELECT ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry
FROM pgr_dijkstra(
'SELECT osm_id AS id, source, target, st_length(way) as cost FROM planet_osm_roads',
34, 3000, false
) as di
JOIN planet_osm_roads pt
ON di.edge = pt.osm_id ;
这是可行的,但是如果我想用我的街道的节点号替换例如 dijkstra 函数中的节点 34,请使用以下查询:
SELECT pl.source::integer
FROM planet_osm_roads pl
WHERE pl.name LIKE ''street_name''
LIMIT 1
并在一起:
SELECT ST_AsGeoJSON(ST_Transform(way, 4326)) AS geometry
FROM pgr_dijkstra(
'SELECT osm_id AS id, source, target, st_length(way) as cost FROM planet_osm_roads',
'SELECT pl.source::integer FROM planet_osm_roads pl WHERE pl.name LIKE ''street_name'' LIMIT 1',
3000, false
) as di
JOIN planet_osm_roads pt
ON di.edge = pt.osm_id ;
它将失败并出现错误:
ERROR: function pgr_dijkstra(unknown, unknown, integer, boolean) is not unique LINE 93: FROM pgr_dijkstra( ^ HINT: Could not choose a best candidate function. You might need to add explicit type casts.
我认为,这是因为我的选择查询返回带有行 ID 和列名的 sql 结果。但也许还有另一个问题。
如何仅将其输出为单个整数?