Order contains same product with different prices.
How to get list of distinct prices per product in order, with one row per product?
I tried
SELECT product, string_AGG(DISTINCT price::text, ',' ORDER BY price)
FROM (VALUES ('A', 100), ('A', 200) , ('B', 200))
orderdetail (product, price)
GROUP BY product
but got error
ERROR: in an aggregate with DISTINCT, ORDER BY expressions must appear in argument list
LINE 1: ...ct, string_AGG(DISTINCT price::text, ',' ORDER BY price DESC...
How to fix this ?
Postgres 9.4 is used.
This is probably required to create answer for How to find changed prices in last two purchase invoices