How to turn a json array into rows in postgres

前端 未结 3 1848
清歌不尽
清歌不尽 2020-12-13 01:44

I have a json array stored in my postgres database. The json look like this:

    [
        {
            \"operation\": \"U\",
            \"taxCode\": \"100         


        
3条回答
  •  眼角桃花
    2020-12-13 02:00

    I post the answer originally written by pozs in the comment section.

    unnest() is for PostgreSQL's array types.

    Instead one of the following function can be used:

    • json_array_elements(json) (9.3+)
    • jsonb_array_elements(jsonb) (9.4+)
    • json[b]_array_elements_text(json[b]) (9.4+)

    Example:

    select * from json_array_elements('[1,true, [2,false]]')
    

    output value

     -------------
     | 1         |
     -------------
     | true      |
     -------------
     | [2,false] |
     -------------
    

    Here where the documentation for v9.4 can be found.

提交回复
热议问题