PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Extraia todos os valores do json na tabela sql


Use json_each() , por exemplo.:
with my_table(items) as (
    values (
    '{"Apple":{"category":"fruit","price":100},"Orange":{"category":"fruit","price":80}}'::json
    )
)

select key, (value->>'price')::numeric as price
from my_table,
json_each(items)

  key   | price 
--------+-------
 Apple  |   100
 Orange |    80
(2 rows)