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