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

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: how to generate a list of distinct scalar values from a column which type is array
Date: 2007-02-22 12:28:01
Message-ID: 20070222122801.GD15488@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Russ Brown 2007-02-22 12:40:23 Re: postgresql vs mysql
Previous Message Sergio Andreozzi 2007-02-22 11:38:50 how to generate a list of distinct scalar values from a column which type is array

Browse pgsql-sql by date

  From Date Subject
Next Message A. Kretschmer 2007-02-22 13:25:36 Re: how to generate a list of distinct scalar values from a column which type is array
Previous Message T E Schmitz 2007-02-22 11:46:52 pg_dump fails (timestamp out of range)