2016-11-16 57 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'