문제

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.

도움이 되었습니까?

해결책

It’s not pretty:

SELECT
  value->'time'
FROM 
  json_array_elements('{"route_json": [{"someKeys": "someValues","time": 123},{"someKeys": "someValues","time": 456}]}'::json->'route_json');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top