From: David Fetter <david@fetter.org>
To: Sergio Andreozzi <sergio.andreozzi@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: how to generate a list of distinct scalar values from a column which type is array
Date: Thu, 22 Feb 2007 08:56:48 -0800
Message-ID: <20070222165648.GE10321@fetter.org> (raw)
In-Reply-To: <2cfc7c940702220338h3eb4ec97p8cd759cb7a36d775@mail.gmail.com>
References: <2cfc7c940702211021u1ba47031l25112a69cfb18338@mail.gmail.com>
<2cfc7c940702220338h3eb4ec97p8cd759cb7a36d775@mail.gmail.com>
On Thu, Feb 22, 2007 at 12:38:50PM +0100, Sergio Andreozzi wrote:
> Dear all,
>
> given a column which type is for instance varchar(20)[],
This is almost never a good design. If you must have an interface
like that, make it VIEW over an aggregate, which you can make
writeable.
> is it possible via SQL to generate the list of distinct scalar
> values?
Yes, but you should fix your design :)
CREATE TABLE foo (ft TEXT[]);
COPY foo(ft) FROM stdin;
{aaa,bb,c}
{dddd,eeee}
{aaa,eeee}
\.
SELECT DISTINCT ft[i]
FROM (
SELECT ft,
generate_series(
array_lower(ft,1),
array_upper(ft,1)
) AS i
FROM foo
) AS bar;
So, yes, you can do it, and no, you shouldn't.
Cheers,
D
--
David Fetter <david@fetter.org> http://fetter.org/
phone: +1 415 235 3778 AIM: dfetter666
Skype: davidfetter
Remember to vote!
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: david@fetter.org, sergio.andreozzi@gmail.com, pgsql-general@postgresql.org
Subject: Re: how to generate a list of distinct scalar values from a column which type is array
In-Reply-To: <20070222165648.GE10321@fetter.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox