在PostgreSQL 9.5中检查对象json中的数组中的值

问题描述:

我有一个包含数组和其他属性的json对象。在PostgreSQL 9.5中检查对象json中的数组中的值

我需要检查我的表的每一行数组的第一个值。

这里是JSON

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

所以我需要以例如获得与对象类型的所有行的一个例子[0] =“需求”和objectId1 = 46

这在表colums

id | relationName | content 

内容列包含json。

只是查询他们?如:

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)