2

My database has beginning and end points [beginning(x,y) ending(x,y)]. I want to create lines from this database for each beginning-end points.

I tried ST_MAKELINE but this function wants location as text as said in this answer. I don't want to enter the points one by one.

How can I pull points from database?

database

1
  • no no, ST_MakeLine requires 2 geometries, which could be constructed from text (as in the linked question) or simply be consumed from existing column(s)
    – JGH
    Commented Oct 19, 2022 at 13:07

1 Answer 1

5

All you need to do is call st_makeline on both geom fields:

SELECT st_makeline(geom, a_geom) as geom
FROM yourtable;
2
  • Thanks! Query returned successfully. I missed this "as geom"part. I got this. Commented Oct 19, 2022 at 20:26
  • @BensuGayret it's not really necessary. If you don't do that, you'll still get a geom field, but it'll be called st_makeline
    – Encomium
    Commented Oct 20, 2022 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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