Returns the Z coordinate of a point geometry as a float.
Syntax
float ST_Z(geometry aPoint);Parameters
| Parameter | Description |
|---|---|
aPoint | The point geometry from which to extract the Z coordinate. |
Returns
Returns the Z coordinate as a float.
Returns NULL if the input is NULL or not a valid point geometry.
Usage notes
aPointmust be a point geometry. Passing any other geometry type returnsNULL.ST_Z preserves Z coordinates and does not strip them from 3D geometries.
Examples
Extract the Z coordinate from a 4D point
SELECT ST_Z('POINT(0 1 2 3)'::geometry);Output:
st_z
------
2
(1 row)The input point has coordinates x=0, y=1, z=2, m=3. ST_Z returns 2, the Z coordinate.
NULL and non-point input behavior
ST_Z returns NULL for both NULL input and non-point geometry types:
SELECT
ST_Z(NULL),
ST_Z('LINESTRING(0 0 1, 1 1 2)'::geometry);Output:
st_z | st_z
------+------
NULL | NULL
(1 row)