【发布时间】:2016-06-07 17:57:03
【问题描述】:
我有一个场景,我需要将一个 json 数组转换为 postgres int 数组并查询它的结果。下面是我的数组
ID DATA
1 {"bookIds" : [1,2,3,5], "storeIds": [2,3]}
2 {"bookIds" : [4,5,6,7], "storeIds": [1,3]}
3 {"bookIds" : [11,12,10,9], "storeIds": [4,3]}
我想将 booksId 数组转换为 int 数组,然后再查询它。在 postgres 9.3 中可以吗?我知道 9.4 + 提供了更多 JSON 支持,但我目前无法更新我的数据库。
下面的查询给我错误
Select data::json->>'bookIds' :: int[] from table
ERROR: malformed array literal: "bookIds"
LINE 1: Select data::json->>'bookIds' :: int[] from table
是否可以在 postgres 9.3 中查询 json 数组中的元素。提前谢谢...
【问题讨论】:
标签: arrays json postgresql postgresql-9.3