Retrieving the coordinates of the MySQL point type

Let’s say you store GeomFromText('POINT(32 -122)') as a column called MY_POINT in a table called MY_TABLE.

Getting the X coordinate (will return 32 in this example):

SELECT ST_X(MY_POINT) as longitude FROM MY_TABLE;

Getting the Y coordinate (will return -122 in this example):

SELECT ST_Y(MY_POINT) as latitude FROM MY_TABLE;

Important: Prior to version 5.6, use X() and Y() instead of ST_X() and ST_Y().

Leave a Comment