【发布时间】:2015-08-07 21:54:26
【问题描述】:
我想要做的是将 29.0 和 34.65 相加并按 P_id 分组
表:transaction_items 列名:借方,P_id 列数据类型:文本、文本 数据:
借记
[{"amount":29.0,"description":"Fee_Type_1"}
[{"amount":"34.65","description":"Fee_Type_1"}
P_id
16
16
我尝试使用此处提到的解决方案 [How to get elements from Json array in PostgreSQL
select transaction_line_items.P_id,
each_attribute ->> 'amount' Rev
from transaction_line_items
cross join json_array_elements(to_json(Debits)) each_section
cross join json_array_elements(each_section -> 'attributes') each_attribute
where (each_attribute -> 'amount') is not null;
但是,我收到一条错误消息,提示“无法解构标量”。
有人可以告诉我如何解析我正在寻找的值吗?
谢谢。
【问题讨论】:
标签: arrays json postgresql