sql >> Base de Datos >  >> RDS >> PostgreSQL

Extraiga todos los valores de json en la tabla sql

Use json_each() , por ejemplo:

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)