2017-09-26 56 views
0

我有一個包含數組和其他屬性的json對象。在PostgreSQL 9.5中檢查對象json中的數組中的值

我需要檢查我的表的每一行數組的第一個值。

這裏是JSON

{"objectID2":342,"objectID1":46,"objectType":["Demand","Entity"]} 

所以我需要以例如獲得與對象類型的所有行的一個例子[0] =「需求」和objectId1 = 46

這在表colums

id | relationName | content 

內容列包含json。

回答

1

只是查詢他們?如:

t=# with table_name(id, rn, content) as (values(1,null,'{"objectID2":342,"objectID1":46,"objectType":["Demand","Entity"]}'::json)) 
select * From table_name 
where content->'objectType'->>0 = 'Demand' and content->>'objectID1' = '46'; 
id | rn |        content 
----+----+------------------------------------------------------------------- 
    1 | | {"objectID2":342,"objectID1":46,"objectType":["Demand","Entity"]} 
(1 row)