Skip to main content

ST_X

Returns the X coordinate of a Point geometry.

Syntax

ST_X(geometry)

Parameters

ParameterTypeDescription
geometryGeometryPoint geometry

Returns

TypeDescription
Float64X coordinate value

Examples

Get X Coordinate

SELECT ST_X(ST_Point(10.5, 20.3));
-- Returns: 10.5

Extract Coordinates from Points

SELECT id, ST_X(geom) as longitude, ST_Y(geom) as latitude
FROM locations;

Filter by X Range

SELECT * FROM points
WHERE ST_X(geom) BETWEEN -122.5 AND -122.0;

Use with Centroid

SELECT id, ST_X(ST_Centroid(geom)) as center_x
FROM polygons;

Notes

  • Only valid for Point geometries
  • For geographic data, X typically represents longitude
  • Returns NULL if geometry is not a Point
  • Works with both GeoArrow Point and WKB Point formats

See Also