Thursday, February 17, 2011

How to sort similar string with words in mixed up order

select distinct on (
array_to_string(
(select array_agg(xx) from (
select lower(x) from unnest(string_to_array(lower(value), ' ')) x order by x
) xx), ' ')
) value
from dup;

table:

create table dup (
value text
);

How to sort similar string with words in mixed up order

select distinct on (array_to_string((select array_agg(xx) from (select lower(x) from
unnest(string_to_array(lower(value), ' ')) x order by x) xx), ' ')) value from dup;