PostgreSQL selects a query to extract latitude and longitude from a point

Which SELECT query should be used to extract latitude and longitude from a point?
I can not use PostGIS.

An example of a point (point type value) stored in a database:

  my_point
 --------------
 (50.850,4.383)

Expected result after query execution:

  lat |  lng
 ---------------
 50.850 |  4.383

The query below works fine, but it does not look effective.

SELECT split_part(trim(my_point::text, '()'), ',', 1)::float AS lat, split_part(trim(my_point::text, '()'), ',', 2)::float AS lng FROM my_table; 
+4
source share
1 answer

Always Read Thin Guides

You can access the two component numbers of the point, as if the point were an array with indices 0 and 1. For example, if tp is a point column, then SELECT p [0] FROM t returns the X coordinate and UPDATE t SET p 1 = ... changes the Y coordinate. In the same way, a value of the box or lseg type can be considered as an array of two point values.

+7
source

Source: https://habr.com/ru/post/1499424/


All Articles