Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I extract some LINESTRING consisting of 3 or more POINTs to several LINESTRINGs each of 2 POINTs in PostGIS?

share|improve this question
up vote 6 down vote accepted

That should do:

SELECT, ST_MakeLine(ST_PointN(the_geom,x),ST_PointN(the_geom,x+1))
FROM original AS a
(SELECT id, generate_series(1, ST_NumPoints(the_geom)-1) AS x 
 FROM original ) AS b
ON =;
share|improve this answer

One option would be to create you one function that iterates through the points and use the funtion MakeLine in order to create a set of geometry.But if your linestrings are not to big check this link out, it should help you :


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.