Search Postgresql Archives

Re: Remove Duplicate Words from a field

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

2011/5/16 Sukuchha Shrestha <sukuchha@xxxxxxxx>:
> Dear All,
> I am new to Postgresql. I have a field with lots of Âdublicate words and i
> want to remove any dublicate word from that field.
> For example, if i have a field with a string " one, one, two, two, three",
> how would i get " one, two, three" only ?
> Any help is much apprecieated !
> Sukuchha


postgres=# CREATE OR REPLACE FUNCTION uniq_worlds(text)
RETURNS text AS $$
SELECT array_to_string(ARRAY(SELECT DISTINCT trim(x) FROM
unnest(string_to_array($1,',')) x),', ')
$$ LANGUAGE sql;
CREATE FUNCTION
Time: 14.281 ms
postgres=# SELECT uniq_worlds('one, two, three, one');
   uniq_worlds
âââââââââââââââââ
 three, two, one
(1 row)

Time: 0.817 ms

Regards

Pavel Stehule

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux