2016-09-19 41 views
1
{"create_channel":"1","update_comm":"1","channels":"*"} 

這是我想要查詢的數據庫字段。查詢存儲在數據庫字段中的字符串中的特定值

將我的查詢是什麼樣的,如果我想選擇所有有"create_channel": "1""update_comm": "1"

其他問題的記錄:

查看下面的字段:

{"create_channel":"0","update_comm":"0","channels":[{"ch_id":"33","news":"1","parties":"1","questions ":"1","cam":"1","edit":"1","view_subs":"1","invite_subs":"1"},{"ch_id":"18","news":"1","parties":"1","questions ":"1","cam":"1","edit":"1","view_subs":"1","invite_subs":"1"}]} 

我如何去找出所有那些在News,parties,questionsCams個部分

回答

1

您可以使用the ->> operator返回一個成員作爲一個字符串:

select * 
from YourTable 
where YourColumn->>'create_channel' = '1' and 
     YourColumn->>'update_comm' = '1' 

找到誰在通道33消息,當事人,問題和凸輪的用戶,您可以使用the @> operator來檢查通道數組包含以下屬性:

select * 
from YourTable 
where YourColumn->'channels' @> '[{ 
      "ch_id":"33", 
      "news":"1", 
      "parties":"1", 
      "questions ":"1", 
      "cam":"1" 
     }]'; 
相關問題