0

I have a jason column in my postgress sql Database. I have several properties in that jason column. I can search properties using below query.

SELECT *  FROM public.object_reference where value->>'name' = 'Sam' and value->>'address' ='home';

But my problem is I have a Array inside that JSON column. That Array has key and value pair. Below is the sample of that array

"attributes": [ {
    "value": "Sam",
    "key": "name"
}, {
    "value": "abc",
    "key": "address"
}, {
    "value": "Singapore",
    "key": "country"
}, {
    "value": "97813245",
    "key": "mobile"
}, {
    "value": "Engineer",
    "key": "position"
},
"id": "1312312",
"type": "Job",
"classid": "1245568956643546788907634"

}

So i need to get the value of name in the attributes array (inside JSON column). This is json type column, not a jsonb type.

1 Answer 1

1

You can deconstruct the array inside de object transforming it in a set of recordet (pseudo table) with json_array_elements:

select pair->>'value'
  from has_json,json_array_elements(obj->'attributes') as pair
  where pair->>'key' = 'name';

You can see a running example at: http://rextester.com/ONJZ8486

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.