gpt4 book ai didi

PostgreSQL select查询从一个点提取经纬度

转载 作者:行者123 更新时间:2023-11-29 11:24:02 25 4
gpt4 key购买 nike

应该使用什么 SELECT 查询从一个点中提取纬度和经度?
我无法使用 PostGIS。

数据库中存储的示例点(点类型值):

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

Expected result after executing the query:

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

The query below works fine but it does not look efficient.

SELECT 
split_part(trim(my_point::text, '()'), ',', 1)::float AS lat,
split_part(trim(my_point::text, '()'), ',', 2)::float AS lng
FROM my_table;

最佳答案

始终 Read The Fine Manuals

It is possible to access the two component numbers of a point as though the point were an array with indexes 0 and 1. For example, if t.p is a point column then SELECT p[0] FROM t retrieves the X coordinate and UPDATE t SET p1 = ... changes the Y coordinate. In the same way, a value of type box or lseg can be treated as an array of two point values.

关于PostgreSQL select查询从一个点提取经纬度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18491802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com