Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 337519FB52E for ; Thu, 22 Feb 2007 09:25:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 87652-07 for ; Thu, 22 Feb 2007 09:25:38 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.188]) by postgresql.org (Postfix) with ESMTP id 7C4C39FB2AC for ; Thu, 22 Feb 2007 09:25:43 -0400 (AST) Received: from [194.25.154.138] (helo=webserv.wug.de) by mrelayeu.kundenserver.de (node=mrelayeu3) with ESMTP (Nemesis), id 0MKxQS-1HKDx23vmJ-00047Y; Thu, 22 Feb 2007 14:25:40 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1HKDx2-0007Mz-00 for pgsql-sql@postgresql.org; Thu, 22 Feb 2007 14:25:36 +0100 Date: Thu, 22 Feb 2007 14:25:36 +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: <20070222132536.GE15488@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+w2eWlU2OG3Y74PsCeFTurGwrQ1/R9MmVYB+/EjARrF49n+gKvMwoFX4vyeFVONYh5eApjX12Au3BZoBOkxZfYfzMNWro1ma6SxjLJm8tHlZj5i0Qa+tD4 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.434 tagged_above=0 required=5 tests=AWL, BAYES_50, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200702/223 X-Sequence-Number: 27557 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 Okay, next solution: test=*# select * from a; c ------------- {aaa,bb,c} {dddd,eeee} {aaa,eeee} (3 rows) test=*# select distinct c[s] from a, generate_series(1,3)s where c[s] is not null; c ------ aaa bb c dddd eeee (5 rows) You need to know the greatest upper dimension of the array, in this case 3, for the generate_series - function. Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net