[GIS] Get Lon Lat values from a GEOGRAPHY data type in PostGIS

coordinate systempostgispostgresql

After storing lon lat values as a GEOGRAPHY data type, how do I retrieve the individual lat lon values?

Failed attempt:

SELECT id, geog, ST_X(geog), ST_Y(geog) FROM locations;

Error:

No function matches the given name and argument types. You might need to add explicit type casts.

Best Answer

The ST_X(point) function only supports the geometry (as for now).

One workaround is to cast the geog to geom using ::geometry.

Hense your query should be like this:

SELECT id, geog, ST_X(geog::geometry), ST_Y(geog::geometry) FROM locations; 

And since it's geog the SRID would be 4326.

Also here's a good source for the geog type.

Related Question