All Products
Search
Document Center

PolarDB:ST_3DLongestLine

Last Updated:Mar 28, 2026

Returns the longest line between two geometry objects in 3D space.

Syntax

geometry ST_3DLongestLine(geometry g1, geometry g2);

Parameters

ParameterDescription
g1The first geometry object. The returned line starts from this object.
g2The second geometry object. The returned line ends at this object.

Usage notes

  • If multiple longest lines exist, the function returns only the first one found.

  • The returned line always starts from g1 and ends at g2.

  • The length of the returned line equals the result of ST_3DMaxDistance when called with the same inputs.

  • Z coordinates are preserved. The function supports 3D objects.

  • The function supports polyhedral surfaces.

Examples

Find the longest line between a point and a line string:

SELECT ST_AsText(
  ST_3DLongestLine(
    'POINT(0 0 0)'::geometry,
    'LINESTRING(0 0 1, 1 1 0)'::geometry
  )
);

Output:

       st_astext
----------------------------
 LINESTRING Z (0 0 0,1 1 0)
(1 row)

See also

  • ST_3DMaxDistance — returns the maximum 3D distance between two geometry objects