Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 34F009FBC7D for ; Thu, 22 Feb 2007 08:28:09 -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 46075-07 for ; Thu, 22 Feb 2007 08:28:05 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by postgresql.org (Postfix) with ESMTP id 5FCF69FB71D for ; Thu, 22 Feb 2007 08:28:05 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu8) with ESMTP (Nemesis), id 0ML31I-1HKD3K3Hxy-0006hs; Thu, 22 Feb 2007 13:28:03 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1HKD3J-0006so-00 for pgsql-sql@postgresql.org; Thu, 22 Feb 2007 13:28:01 +0100 Date: Thu, 22 Feb 2007 13:28:01 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: how to generate a list of distinct scalar values from a column which type is array Message-ID: <20070222122801.GD15488@a-kretschmer.de> References: <2cfc7c940702211021u1ba47031l25112a69cfb18338@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2cfc7c940702211021u1ba47031l25112a69cfb18338@mail.gmail.com> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! X-Message-Flag: "Windows" is not the answer. "Windows" is the question and the answer is "no"! User-Agent: Mutt/1.5.9i X-Provags-ID: kundenserver.de abuse@kundenserver.de login:51ea9561fc3f6d9539a2acd743e4748c X-Provags-ID2: V01U2FsdGVkX1+GMMhi8APzkZFgeppfu/le+SvhZtP+YdQ9ZzTZYxwh824yiDC96ws7s+VQj4h5fyniwvW5WCEl9xY9Vr88uU//tXsT60avUID9rJoHa3PR3yXxNFgUIt3f X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.447 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200702/222 X-Sequence-Number: 27556 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