Re: how to generate a list of distinct scalar values from a column which type is array

Поиск
Список
Период
Сортировка
От A. Kretschmer
Тема Re: how to generate a list of distinct scalar values from a column which type is array
Дата
Msg-id 20070222122801.GD15488@a-kretschmer.de
обсуждение исходный текст
Ответ на how to generate a list of distinct scalar values from a column which type is array  ("Sergio Andreozzi" <sergio.andreozzi@gmail.com>)
Список pgsql-sql
am  Wed, dem 21.02.2007, um 19:21:09 +0100 mailte Sergio Andreozzi folgendes:
> Dear all,
> 
> given a column which type is for instance varchar(20)[], is there any SQL
> command that let me generate the list of distinct scalar values?
> 
> 
> e.g.:
>              col1
> row 1: (aaa, bb, c)
> row 2: (dddd, eeee)
> row 3: (aaa, eeee)
> 
> the query should return:
> 
> aaa
> bb
> c
> dddd
> eeee
> 
> if not, I guess the approach is to use stored procedure. Any code snippet/
> suggestion?

You can, for each row, split the array into the elements with a loop
over array_lower, array_upper, returns this element. Yes, this is a
setof-function. Than you can do a simple select distinct * from
your_function.


I hope this may help you.


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net


В списке pgsql-sql по дате отправления:

Предыдущее
От: T E Schmitz
Дата:
Сообщение: pg_dump fails (timestamp out of range)
Следующее
От: "A. Kretschmer"
Дата:
Сообщение: Re: how to generate a list of distinct scalar values from a column which type is array