【发布时间】:2017-07-10 19:19:00
【问题描述】:
我有一个 postgresql 表,它有一个 json 格式的列。
示例列值:
{"Apple":{"category":"fruit","price":100},"Orange":{"category":"fruit","price":80}}
现在我想选择这一列,并为每一行中的所有项目提取"price"。
查询获取列:
select items from my_table
要提取特定项目的 json 值,我可以使用
select items -> 'Orange' -> 'price' as price
from my_table
但是如何提取所有商品(Apple、Orange)的价格?可能是一个数组。
【问题讨论】:
标签: sql json postgresql