All Products
Search
Document Center

PolarDB:ST_PointN

Last Updated:Mar 28, 2026

Returns the Nth point of a LineString or circular LineString object.

Syntax

geometry ST_PointN(geometry aLinestring, integer n)

Parameters

ParameterDescription
aLinestringThe LineString object or circular LineString object to query.
nThe index of the point to return. Negative values count backward from the end: -1 returns the last point.

Usage notes

  • Returns NULL if aLinestring is not a LineString.

  • To get the Nth point of each LineString in a MultiLineString, combine ST_PointN with ST_Dump.

  • Supports circular strings and curves.

  • Supports 3D geometries and preserves Z coordinates.

Examples

Return the first point of a LineString:

SELECT ST_AsText(ST_PointN('LINESTRING(0 0,2 2)'::geometry, 1));
 st_astext
------------
 POINT(0 0)
(1 row)

Return the last point using a negative index:

SELECT ST_AsText(ST_PointN('LINESTRING(0 0,2 2)'::geometry, -1));
 st_astext
------------
 POINT(2 2)
(1 row)