Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 4DA56632D8B for ; Wed, 24 Feb 2010 09:09:33 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 08534-01-3 for ; Wed, 24 Feb 2010 13:09:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from moutng.kundenserver.de (moutng.kundenserver.de [212.227.126.171]) by mail.postgresql.org (Postfix) with ESMTP id 99A18633B67 for ; Wed, 24 Feb 2010 09:09:12 -0400 (AST) Received: from webserv.wug.de ([194.25.154.138]) by mrelayeu.kundenserver.de (node=mreu0) with ESMTP (Nemesis) id 0LcCDx-1NIbCK2HUj-00jZAz; Wed, 24 Feb 2010 14:09:10 +0100 Received: from kretschmer by webserv.wug.de with local (Exim 3.36 #1) id 1NkGzF-0005sC-00 for pgsql-sql@postgresql.org; Wed, 24 Feb 2010 14:09:09 +0100 Date: Wed, 24 Feb 2010 14:09:09 +0100 From: "A. Kretschmer" To: pgsql-sql@postgresql.org Subject: Re: join with an array Message-ID: <20100224130909.GL22249@a-kretschmer.de> References: <20100224124023.GA16500@apartia.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100224124023.GA16500@apartia.fr> X-OS: Debian/GNU Linux - weil ich es mir Wert bin! User-Agent: Mutt/1.5.9i X-Provags-ID: V01U2FsdGVkX18ApCqajHHDPH/Rbr6yjjzuuOV74ZSfE9ZEcoZ pVPnxNEKGK9uZdDLXTMVJVCyUiGNroU5DZvgou6S5lsNwUIw2p F+cZZEJtZ/T1URECtoyRQ== X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.74 tagged_above=-10 required=5 tests=BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 201002/90 X-Sequence-Number: 33689 In response to Louis-David Mitterrand : > Hi, > > I'm trying the following query: > > select array_agg(t1.id) from table1 t1 join table2 t2 on (t2.id = any(array_agg)) group by t1.col1; > > but I get this error: ERROR: column "array_agg" does not exist > > I tried aliasing array_agg(t1.id) without success. > > Thanks for any suggestions, I can't really understand what you want to achieve, but maybe this is what you are looking for: test=*# select * from a; id | v ----+--- 1 | 1 2 | 1 3 | 1 4 | 1 5 | 2 6 | 2 (6 rows) test=*# select * from b; id ---- 1 3 (2 rows) test=*# select array_agg(a.id), v from a join b on (b.id in (select a.id from a)) group by a.v; array_agg | v -------------------+--- {1,2,3,4,1,2,3,4} | 1 {6,5,5,6} | 2 (2 rows) Question: you are 'pif' in the irc-channel? Regards, Andreas -- Andreas Kretschmer Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header) GnuPG: 0x31720C99, 1006 CCB4 A326 1D42 6431 2EB0 389D 1DC2 3172 0C99