I'm having problems converting this from Oracle to PostgreSQL. I've tried using STRING_AGG, but i'm not having any success. I believe there's also an issue with REGEXP_REPLACE. Can someone help?
REGEXP_REPLACE(
LISTAGG(column_name, ',') WITHIN GROUP (ORDER BY column_name),
'([^,]+)(,\1)*(,|$)',
'\1\3'
)
Perhaps you want something like this:
string_agg(DISTINCT column_name, ',' ORDER BY column_name)