How to get elements from Json array in PostgreSQL

后端 未结 3 924
清酒与你
清酒与你 2021-01-31 11:04

I have searched quite much on this and still unanswerable. I\'m using PostgreSQL. Column name is \"sections\" and column type is json[] in below example.

My column looks

3条回答
  •  一向
    一向 (楼主)
    2021-01-31 11:20

    And also, if there was a key value map data in array:

    select each_data -> 'value' as value3 
    from t cross join jsonb_array_elements(t.sections -> 'attributes') each_attribute 
    where each_attribute -> 'key' = '"attrkey3"'
    

    I am mentioning this because the great answer also provided a perfect solution for my case. By the way, also be aware of jsonb_array.. method for jsonb type attribute.

提交回复
热议问题