2016-11-16 56 views
0

我在我的表的文档有jsonb列(gppermission)数据作为JSON数组,它包含数据搜索一个JSON数组中jsonb列具有posgresql

[{"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数组是不同

请帮助...

+0

[对于内部JSON类型的数组元素的查询(的可能的复制http://stackoverflow.com/questions/22736742/query-for-array-elements-inside-json-类型) – cske

回答

0

我得到了一个解决方案,这可能不是唯一的解决办法来做到这一点。

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'