【问题标题】:Search for a json array in jsonb column having data as json array in PostgreSQL在 PostgreSQL 中的 jsonb 列中搜索 json 数组,其中数据为 json 数组
【发布时间】:2016-11-16 07:48:12
【问题描述】:

我的表格文档中有一个 jsonb 列(gppermission),其中包含的数据为

[{"Deny": "true", "Allow": "false", "GroupName": "Group 1 "}, 
 {"Deny": "false", "Allow": "true", "GroupName": "Group 2 "}, 
 {"Deny": "false", "Allow": "true", "GroupName": "Group 3 "}, 
 {"Deny": "true", "Allow": "false", "GroupName": "Group 4 "}]

我需要在这个数据中搜索

{"Deny": "false", "Allow": "true", "GroupName": "Group 3 "}

我尝试了以下查询。但没有结果:(

select * from doc as dc ,jsonb_array_elements(dc.gppermission) as e(gp) where e.gp = '{"Deny":"false","Allow":"true","GroupName":"Group 3"}'

看到 Query for array elements inside JSON type 但它有一个“对象”引用,我的 json 数组不同

请帮忙...

【问题讨论】:

标签: postgresql postgresql-9.4 jsonb


【解决方案1】:

我有一个解决方案,这可能不是唯一的解决方案。

select * from doc as dc ,jsonb_array_elements(dc.gppermission) as e(gp) where e.gp ->>'Deny'='false' and e.gp ->>'Allow'='true' and e.gp ->>'GroupName'='Group 1'

【讨论】:

    猜你喜欢
    • 2015-08-15
    • 1970-01-01
    • 2021-09-27
    • 2016-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-12
    相关资源
    最近更新 更多