0

I have an json object containing an array and others properties.

I need to check the first value of the array for each line of my table.

Here is an example of the json

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

So I need for example to get all lines with ObjectType[0] = 'Demand' and objectId1 = 46.

This the the table colums

id |  relationName | content

Content column contains the json.

1 Answer 1

1

just query them? like:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.