Postgre Group由json数组列

时间:2016-06-28 18:36:57

标签: arrays json postgresql

我很难理解postgres json数组类型。如何使用json数组列进行组。例如:

select product, avg(sales)
from Order 
group by product

"Error: could not identify an equality operator for type json"

--Order--
id | sales | product                 
1  | 36    | ["874746", "474657"] 
2  | 120   | ["874748"] 
3  | 15    | ["874736", "474654"] 

1 个答案:

答案 0 :(得分:4)

您需要使用jsonb(二进制)9.4 +:

select product::jsonb, avg(sales)
from Order 
group by product::jsonb