【发布时间】:2020-08-29 18:05:24
【问题描述】:
我目前将数据存储在 postgres db 的 jsonb 列中,格式如下:
{"ids": [4, 3, 2, 1]} 其中值是一个整数数组。
我希望做以下事情:
-
找到该列在值中包含值 4 的行
'ids' 键的数组。 -
在“ids”键的值数组中找到列包含值 2,3 和 1 的行。
我最近的尝试使用以下
select * from tablename WHERE (column_name -> ids)::integer[] && ARRAY[1,3]
这给了我一个类型转换错误 ::integer[] ERROR: cannot cast type jsonb to integer[]
我怀疑我试图投射“ids”部分并且需要更深入,但我不确定如何(如果这甚至是正确的方法)。
【问题讨论】:
标签: postgresql jsonb