You can create an array from your csv string using unnest
, wrap the elements with quote_literal()
and then aggregate them again. You can achieve this with a subquery ..
SELECT array_to_string(array_agg(i),',') FROM
(SELECT quote_literal(unnest(string_to_array(user_groups,',')))
FROM ticker_information) j (i);
array_to_string
---------------------
'1','2','3','4','5'
Or with a LATERAL
:
SELECT array_to_string(array_agg(quote_literal(j.i)),',')
FROM ticker_information,
LATERAL unnest(string_to_array(user_groups,',')) j (i);
array_to_string
---------------------
'1','2','3','4','5'
Another option would be with regular expressions.. but it could get nasty if the elements of your csv contain commas.
Demo: db<>fiddle