2

I'm having a hard time understanding Postgres json array type. How to do a group by using json array column. For example:

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 Answer 1

5

You need to use jsonb (binary) 9.4+:

select product::jsonb, avg(sales)
from Order 
group by product::jsonb
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.