# ST_X function

The ST_X function takes a point as an input parameter and returns its X coordinate. You can optionally indicate an X coordinate as input parameter in addition to the point and the function returns the point itself with its X coordinate set to the given value.

If the given point is null or is empty, then null is returned.

This function can also be called as a method.

## Parameters

point
A value of type ST_Point for which the X coordinate is returned or modified.
x_coordinate
A value of type DOUBLE that represents the new X coordinate for point.

## Return types

• DOUBLE, if x_coordinate is not specified
• db2gse.ST_Point, if x_coordinate is specified

## Examples

Example 1
This example illustrates use of the ST_X function. Geometries are created and inserted into the SAMPLE_POINTS table.
``````
SET CURRENT FUNCTION PATH = CURRENT FUNCTION PATH, db2gse
CREATE TABLE sample_points (id INTEGER, geometry ST_Point)

INSERT INTO sample_points (id, geometry)
VALUES (1, ST_Point (2, 3, 32, 5, 1) ),
(2, ST_Point (4, 5, 20, 4, 1) ),
(3, ST_Point (3, 8, 23, 7, 1) )
``````
Example 2
This example finds the X coordinates of the points in the table.
``````
SELECT id, ST_X (geometry) X_COORD
FROM sample_points
``````
Results:
``````
ID         X_COORD
---------- ----------------------
1 +2.00000000000000E+000
2 +4.00000000000000E+000
3 +3.00000000000000E+000

``````
Example 3
This example returns a point with its X coordinate set to 40.
``````
SELECT id, CAST( ST_AsText( ST_X (geometry, 40)) AS VARCHAR(60) )
X_40
FROM sample_points
WHERE id=3
``````
Results:
``````
ID         X_40
------ ----------------------------------------------------------
3 POINT ZM ( 40.00000000 8.00000000 23.00000000 7.00000000)
``````