D
D
Devolobnya2021-10-07 07:28:22
PostgreSQL
Devolobnya, 2021-10-07 07:28:22

How to calculate distance in select array?

Hello.
There is a table with a track

CREATE TABLE positions
 (
id INTEGER GENERATED BY DEFAULT AS IDENTITY,
date_add TIMESTAMP WITHOUT TIME ZONE NOT NULL DEFAULT NOW(),
latitude DOUBLE PRECISION NOT NULL,
longitude DOUBLE PRECISION NOT NULL,
current_point_n geometry
);
current_point_n=st_geometryfromtext('POINT('|| latitude ||' '|| longitude ||')',4326);


Tried to execute
SELECT ST_Distance( ARRAY( SELECT current_point_n FROM positions ORDER BY id) );

but i get an error
function st_distance(geometry[]) does not exist


If you try to build a linestring and calculate the length of the line
SELECT st_Length(ST_MakeLine
( ARRAY( SELECT current_point_n FROM positions ORDER BY id) ));

I get the wrong result.
How can one correctly calculate the sum of distances between points in a select?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question