I have a query that returns a set of rows with a combination of the letters A, E, I and L. That combination are Portuguese mneumonics for Alterar, Excluir, Incluir, and Listar. The column value can vary between A, AE, AEL, AELI... L, LI, LIA, LIAE.
In the example illustrated below I would like to be able to get a unique string with all repeated letters removed. So the result would be AELI, a merge of all rows.
My first attempt was using the combination of the functions array_to_string and array_agg.
select array_to_string(array_agg(colmn), '') from mytable;
then I used the regexp_matches function for matching only one character of the same letter, but with no success, because returned AELA.
select regexp_matches('AELAEILI', '[?AEIL][?AEIL][?AEIL][?AEIL]');
Here the examples explanated above.
Note
That problem explanated here is a piece of a great sql instruction. This sqlfiddle is my effort of simulating my real problem.

I think this can be achieved by using the
regexp_split_to_tablepostgresql function.From the docs:
So, if have the following data:
The result of the query
SELECT regexp_split_to_table(col, '') as colwill be
After managing to split the words like that, filtering the duplicates is pretty simple by adding the DISTINCT statement:
The result of this query is going to be
At the end we can convert the result rows to a single string with the following code: