Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have postgreSQL 9.3 and working with json, my field json in DB looks like:

{
    "route_json": [
        {
            "someKeys": "someValues",
            "time": 123
        },
        {
            "someKeys": "someValues",
            "time": 123
        }, ... N
    ]
}

In my case I need to catch the 'time' element from each element of route_json array and set them in new array. Is there any way to do this.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

It’s not pretty:

SELECT
  value->'time'
FROM 
  json_array_elements('{"route_json": [{"someKeys": "someValues","time": 123},{"someKeys": "someValues","time": 456}]}'::json->'route_json');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.