Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 8503D9FBDE3 for ; Thu, 22 Feb 2007 12:57:10 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 96129-02 for ; Thu, 22 Feb 2007 12:56:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from fetter.org (start.fetter.org [66.92.188.65]) by postgresql.org (Postfix) with ESMTP id 0462A9FBED9 for ; Thu, 22 Feb 2007 12:56:49 -0400 (AST) Received: by fetter.org (Postfix, from userid 500) id 3BF4DF3D99C; Thu, 22 Feb 2007 08:56:48 -0800 (PST) Date: Thu, 22 Feb 2007 08:56:48 -0800 From: David Fetter To: Sergio Andreozzi Cc: pgsql-general@postgresql.org Subject: Re: how to generate a list of distinct scalar values from a column which type is array Message-ID: <20070222165648.GE10321@fetter.org> References: <2cfc7c940702211021u1ba47031l25112a69cfb18338@mail.gmail.com> <2cfc7c940702220338h3eb4ec97p8cd759cb7a36d775@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2cfc7c940702220338h3eb4ec97p8cd759cb7a36d775@mail.gmail.com> User-Agent: Mutt/1.4.2.1i X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.222 tagged_above=0 required=5 tests=AWL, BAYES_50 X-Spam-Level: X-Archive-Number: 200702/1241 X-Sequence-Number: 109731 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 http://fetter.org/ phone: +1 415 235 3778 AIM: dfetter666 Skype: davidfetter Remember to vote!