如何为jsonb列中的数组编写postgreselect查询?

bqf10yzr  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(310)

我在postgres中查询json数组时遇到了一些麻烦。例如:
给一张postgres表 foobar 关于jsonb列 data 就像。。。

db=# select * from foobar;
 id |             data              
----+--------------------------------------------
  1 | [[true, true], [true, false]] 
  2 | [[true, true], [true, true]]  
  3 | [[true, true], [true, true], [true, true]]  
(3 rows)

如何编写一个select查询,只选择只包含 true 中每个数组中的值 data 其数组长度为2(i、 e.,世界其他地区 id = 2 在上面的例子中)?

mepcadol

mepcadol1#

只需将其与参考进行比较:

select *
from foobar
where data = '[[true, true], [true, true]]'

相关问题