【问题标题】:PostgreSQL select query to extract coordinates from a pointPostgreSQL 选择查询从一个点提取坐标
【发布时间】:2019-09-27 05:22:13
【问题描述】:

我有下表,postgres 文本数据类型列中的坐标值

create table xy(coordinates text)

insert into xy values('1234567.67890,45678.901234;7890123.67890,67890.801234;5678902.67834,90123.101234')
insert into xy values('3214567.234721,12456.890123')
insert into xy values('4532890.783421,453212.23412')

每一行都包含任何坐标。我想用分号分割。

我想要下面的输出。

x
-
1234567.67890,45678.901234
7890123.67890,67890.801234
5678902.67834,90123.101234
3214567.234721,12456.890123
4532890.783421,453212.23412

【问题讨论】:

  • 你真的还在使用 Postgres 9.1 吗? Postgres 9.1 是no longer supported,您应该立即计划升级。

标签: sql split postgresql-9.1


【解决方案1】:

您可以为此使用string_to_array()unnest()

select t.x
from xy, unnest(string_to_array(xy.coordinates, ';')) as t(x);

在线示例:https://rextester.com/COI94042

编辑:我认为使用古老的 9.1 版本应该可以:

select unnest(string_to_array(xy.coordinates, ';')) as x
from xy; 

【讨论】:

  • 错误:FROM 中的函数表达式不能引用相同查询级别的其他关系 LINE 2: from xy, unnest(string_to_array(xy.coordinates, ';')) as t(x...
  • @Ram:这是由于您的 Postgres 版本不受支持且过时所致。查看我的编辑
  • ok.my 版本支持 split_part 功能,有没有办法使用 split_part 功能或任何其他功能来实现我的逻辑
  • @Ram: 9.1 也支持string_to_array
猜你喜欢
  • 2013-08-31
  • 2019-02-19
  • 2018-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多