ST_POINTN
Introduced or updated: v1.2.458
Returns a Point at a specified index in a LineString.
Syntax
ST_POINTN(<geometry_or_geography>, <index>)
Arguments
| Arguments | Description |
|---|---|
<geometry_or_geography> | The argument must be an expression of type GEOMETRY or GEOGRAPHY that represents a LineString. |
<index> | The index of the Point to return. |
note
The index is 1-based, and a negative index is uesed as the offset from the end of LineString. If index is out of bounds, the function returns an error.
Return Type
Geometry.
Examples
GEOMETRY examples
SELECT
ST_POINTN(
ST_GEOMETRYFROMWKT(
'LINESTRING(1 1, 2 2, 3 3, 4 4)'
),
1
) AS pipeline_pointn;
┌─────────────────┐
│ pipeline_pointn │
├─────────────────┤
│ POINT(1 1) │
└─────────────────┘
SELECT
ST_POINTN(
ST_GEOMETRYFROMWKT(
'LINESTRING(1 1, 2 2, 3 3, 4 4)'
),
-2
) AS pipeline_pointn;
┌─────────────────┐
│ pipeline_pointn │
├─────────────────┤
│ POINT(3 3) │
└─────────────────┘
GEOGRAPHY examples
SELECT
ST_POINTN(
ST_GEOGFROMWKT(
'LINESTRING(1 1, 2 2, 3 3, 4 4)'
),
2
) AS pipeline_pointn;
┌─────────────────┐
│ pipeline_pointn │
├─────────────────┤
│ POINT(2 2) │
└─────────────────┘