Hey! This content applies only to previous CARTO products

Please check if it's relevant to your use case. On October 2021 we released a new version of our platform.
You can learn more and read the latest documentation at docs.carto.com

Questions  /  Working with Data  /  PostGIS

How to create straight lines between points

Use SQL to connect points with straight lines.

You can use the ST_MakeLine PostGIS function to connect points with lines using SQL:

SELECT a.cartodb_id,
       ST_MakeLine(
           a.the_geom_webmercator,
           b.the_geom_webmercator
       ) as the_geom_webmercator,
       a.name as origin,
       b.name as destination
  FROM ( SELECT *
           FROM populated_places
          WHERE name = 'Paris'
       ) as a,
       ( SELECT *
           FROM populated_places
          WHERE name = 'Madrid'
       ) as b

lines