Assume I have these rows:
I want to create single text value which get unique value from all rows.
How do we do it with query?
select array_agg(val) from ( select distinct unnest(string_to_array(my_column, ',')) val from my_table) x
A breakdown of what's going on:
string_to_array()splits the string, using the specified delimiter, into a true array
unnest()turns an array into separate rows - one for each element
distinctremoves duplicate rows
array_agg()joins all rows into a single CSV string (typically you would us a
group byclause, but no need here as there's only one group)