Return the X coordinate of a POINT geometry.
ST_X(point)
## Overview Returns the X ordinate of a POINT geometry as a DOUBLE. For geographic data X corresponds to longitude in decimal degrees. The X value represents east/west position: negative values are west of the prime meridian, positive values are east. ST_X is the inverse of the first argument of ST_MAKE_POINT. Together with ST_Y it round-trips a POINT geometry back into its two numeric coordinates. ## When to use ST_X vs. alternatives - **ST_X** (this function): extract the X (longitude) coordinate from a POINT. - **ST_Y**: extract the Y (latitude) coordinate from a POINT. - **ST_AS_TEXT**: serialize the entire geometry as WKT when you need both coordinates and their layout. - **Direct column access**: if your table already stores lng and lat as separate DOUBLE columns, there is no need to build a POINT and then extract. ## Behavior - Returns a DOUBLE. - Works only on POINT geometries. LINESTRING, POLYGON, or multi-geometries raise an error or return NULL depending on runtime mode; use a different ST_ function to reduce them to a POINT first (for example the centroid). - Returns NULL if the input geometry is NULL. - The value is the raw X ordinate stored in the geometry; no CRS transformation is performed. - On an empty POINT, behavior is implementation-defined; prefer filtering out empty geometries explicitly. ## Input format - Accepts any POINT built with ST_MAKE_POINT, parsed with ST_GEOM_FROM_TEXT, or returned by other ST_ functions that produce a POINT. - The caller is responsible for tracking whether X means longitude, easting, or something else entirely based on the CRS of the input. ## Compatibility - Matches the OGC Simple Features ST_X semantics for 2D POINT geometries. - Returns the raw ordinate value with no unit conversion, matching other SQL engines that expose ST_X.
| Name | Type | Description |
|---|---|---|
point | Specifies a POINT geometry whose X coordinate to extract. For geographic data X is longitude in decimal degrees. Non-POINT inputs raise an error or return NULL depending on runtime mode. |
-- X is longitude for geographic data; expect -74.006.
SELECT ST_X(ST_MAKE_POINT(-74.0060, 40.7128)) AS lng;
-- WKT coordinate order is (x y), so the first number is X.
SELECT ST_X(ST_GEOM_FROM_TEXT('POINT(2.3522 48.8566)')) AS lng;
-- Denormalize a POINT column into lng/lat columns for downstream tooling.
SELECT id,
ST_X(geom) AS lng,
ST_Y(geom) AS lat
FROM geo.catalog.poi;
-- X > 0 selects everything east of longitude 0.
SELECT id
FROM geo.catalog.poi
WHERE ST_X(geom) > 0;
-- Reconstruct the original point from its coordinates.
SELECT ST_MAKE_POINT(ST_X(geom), ST_Y(geom)) AS geom2
FROM geo.catalog.poi;
-- A NULL geometry returns NULL.
SELECT ST_X(CAST(NULL AS GEOMETRY)) AS lng;