如何从 json_extract_array 中删除双引号

问题描述

我有一组需要采用 Geojson 格式但没有双引号的坐标,我也只能在这个数据集上进行选择。 这行代码

json_extract_array(st_asgeojson(st_makeline( array_agg(st_geogpoint(locs.lon,locs.lat) order by locs.date))),'$.coordinates') as geo

给我这个

[
  "[-8.6359,40.6371716666667]","[-8.63589166666667,40.637165]","[-8.63589333333333,40.6371583333333]","[-8.63589,"[-8.63588833333333,"[-8.635885,40.6371766666667]","[-8.63588166666667,40.63718]"
]

我需要它变成这样

[
  [-8.6359,40.6371716666667],[-8.63589166666667,40.637165],[-8.63589333333333,40.6371583333333],[-8.63589,[-8.63588833333333,[-8.635885,40.6371766666667],[-8.63588166666667,40.63718]
]

解决方法

好的,我找到了答案,以防其他人遇到同样的问题。 使用 json_extract 而不是 json_array_extract。这将删除双引号

json_extract(st_asgeojson(st_makeline( array_agg(st_geogpoint(locs.lon,locs.lat) order by locs.date))),'$.coordinates') as geo