-- The endpoint_test table stores the gid integer column, which uniquely
-- identifies each row and the ln1 ST_LineString column that stores
-- linestrings.

CREATE TABLE endpoint_test (gid integer,
                            ln1 ST_LineString);

-- The INSERT statements insert linestrings into the endpoint_test table.
-- The first linestring doesn't have Z coordinates or measures,
-- while the second one does.

INSERT INTO endpoint_test VALUES( 
   1, 
   ST_LineFromText('linestring (10.02 20.01,23.73 21.92,30.10 40.23)',1000)
);

INSERT INTO endpoint_test VALUES( 
   2, 
   ST_LineFromText('linestring zm (10.02 20.01 5.0 7.0,23.73 21.92 6.5 7.1,30.10 40.23 6.9 7.2)',1000) 
);

-- The query lists the gid column with the output of the ST_EndPoint function.
-- The ST_EndPoint function generates a ST_Point geometry. 

SELECT gid, ST_EndPoint(ln1) Endpoint 
   FROM endpoint_test;
