How to sort the result from string_agg() November 16, 2022 by Tarik With postgres 9.0+ you can write: select string_agg(product,' | ' order by product) from "tblproducts" Details here.