Answer the question
In order to leave comments, you need to log in
How to sort by array in PostgreSQL?
There are two tables. The first planet_osm_ways:
id :: bigint, nodes :: bigint[], tags :: text[] - it contains the object and the nodes field (bigint array) contains a list of the object's points in the required order.
The second table is planet_osm_nodes - it contains points with coordinates.
id :: bigint, lat::bigint, lon::bigint
Request:
select
pon.id,
ST_FlipCoordinates(ST_Transform(ST_GeomFromText('POINT(' || lon / 100 || ' ' || lat / 100 || ')', 3785), 4326)) as coords
from
planet_osm_ways AS pow
left join planet_osm_nodes AS pon on pon.id = any (pow.nodes)
where
pow.id = 128676234
order by
pow.nodes -- ??
Answer the question
In order to leave comments, you need to log in
If I understand correctly, perhaps this will help:
You can sort by the results of some function. That is,
select
...
from
planet_osm_ways AS pow
left join planet_osm_nodes AS pon on pon.id = any (pow.nodes)
where
pow.id = 128676234
order by
my_cool_sorting_func( pow.nodes );
Where my_cool_sorting_func is a function that takes an array as input and returns a result (for example, int ), which will determine the sort order
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question