Reputation: 1
I want to remove duplicate from a string separated with comma with regexp_replace function in Postgres
Input string: emarian, eiulian, evasile, emarina,emarian, eiulian, evasile, emarina
Desired output: emarian, eiulian, evasile, emarina
Please can someone help me!
Desired string:emarian, eiulian, evasile, emarina
Sincerely, I'm not familiar cu regexp_replace
Upvotes: 0
Views: 59
Reputation: 31
You can use combination of array functions and distinct to achieve this
Eg query
SELECT array_to_string(array_agg(DISTINCT word), ', ')
FROM regexp_split_to_table('emarian, eiulian, evasile, emarina, emarian, eiulian, evasile, emarina', ', ') AS word;
The above query splits the string by the delimititer to value list and performs distinct and then converts back to string.
I would not recommend regex_replace for this.
Upvotes: 2