PostgreSQL
 sql >> Datenbank >  >> RDS >> PostgreSQL

Extrahieren Sie alle Werte aus JSON in der SQL-Tabelle

Verwenden Sie json_each() , z. B.:

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)