The ST_MAKELINE function creates a LINESTRING geography object from specified endpoints.
Syntax
The ST_MAKELINE function has two signatures. Select the one that matches your use case.
Signature 1: Creates a LINESTRING geography object from two endpoints.
GEOGRAPHY ST_MAKELINE(GEOGRAPHY <point1>, GEOGRAPHY <point2>)Signature 2: Creates a LINESTRING geography object from an ARRAY of one or more endpoints.
GEOGRAPHY ST_MAKELINE(ARRAY<GEOGRAPHY> <points>)
Parameters
point1, point2: Required. A POINT geography object. Use the ST_GEOGPOINT, ST_GEOGFROMWKB, or ST_GEOGFROMTEXT functions to create these objects.
points: Required. An ARRAY of POINT geography objects. The ARRAY must contain at least one element. Use the ST_GEOGPOINT, ST_GEOGFROMWKB, or ST_GEOGFROMTEXT functions to create these objects.
Return value
Returns a LINESTRING geography object. The following rules apply:
Returns NULL if any input GEOGRAPHY parameter is NULL, or if the input ARRAY or any of its elements is NULL.
If the input consists of two identical points or an ARRAY with a single point, the result degenerates into a POINT geography object.
The precision limitations of the S2 Geography Library may cause minor discrepancies between the input and output.
Examples
Example 1: Create a LINESTRING geography object from two endpoints.
-- Provide two different endpoints to create a LINESTRING. SELECT ST_MAKELINE(ST_GEOGPOINT(270, 0), ST_GEOGPOINT(1, 1)); -- Result: +-------------------------+ | _c0 | +-------------------------+ | LINESTRING (-90 0, 1 1) | +-------------------------+ -- Provide two identical endpoints. The result degenerates to a POINT. SELECT ST_MAKELINE(ST_GEOGPOINT(1, 1), ST_GEOGPOINT(1, 1)); -- Result: +-------------+ | _c0 | +-------------+ | POINT (1 1) | +-------------+Example 2: Create a LINESTRING geography object from an ARRAY of one or more endpoints.
-- Provide an ARRAY of points to create a LINESTRING. SELECT ST_MAKELINE(ARRAY(ST_GEOGPOINT(0, 0), ST_GEOGPOINT(1, 1), ST_GEOGPOINT(2, 2))); -- Result: +----------------------------+ | _c0 | +----------------------------+ | LINESTRING (0 0, 1 1, 2 2) | +----------------------------+ -- Provide an ARRAY with a single element. The result degenerates to a POINT. SELECT ST_MAKELINE(ARRAY(ST_GEOGPOINT(0, 0))); -- Result: +-------------+ | _c0 | +-------------+ | POINT (0 0) | +-------------+