Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 8139E633145 for ; Wed, 24 Feb 2010 09:35:01 -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 12513-06 for ; Wed, 24 Feb 2010 13:34:50 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sargon.lncsa.com (mail.lncsa.com [213.215.28.11]) by mail.postgresql.org (Postfix) with ESMTP id D42A5632A1B for ; Wed, 24 Feb 2010 09:34:50 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by sargon.lncsa.com (Postfix) with ESMTP id F0EE3301E6CD for ; Wed, 24 Feb 2010 14:34:48 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at lncsa.com Received: from sargon.lncsa.com ([127.0.0.1]) by localhost (sargon.lncsa.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RGas8fEacnve for ; Wed, 24 Feb 2010 14:34:48 +0100 (CET) Received: from zenon.apartia.fr (zenon.apartia.fr [10.0.3.1]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "zenon.apartia.fr", Issuer "ca.apartia.fr" (verified OK)) by sargon.lncsa.com (Postfix) with ESMTP id CE5C7300E355 for ; Wed, 24 Feb 2010 14:34:48 +0100 (CET) Received: from galba.apartia.fr (galba.apartia.fr [10.0.3.119]) by zenon.apartia.fr (Postfix) with ESMTP id 866FA59336C7D for ; Wed, 24 Feb 2010 14:34:48 +0100 (CET) Received: by galba.apartia.fr (Postfix, from userid 1000) id 46D101D427; Wed, 24 Feb 2010 14:34:48 +0100 (CET) Date: Wed, 24 Feb 2010 14:34:48 +0100 From: Louis-David Mitterrand To: pgsql-sql@postgresql.org Subject: Re: join with an array Message-ID: <20100224133447.GA18435@apartia.fr> Mail-Followup-To: pgsql-sql@postgresql.org References: <20100224124023.GA16500@apartia.fr> <20100224130909.GL22249@a-kretschmer.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100224130909.GL22249@a-kretschmer.de> User-Agent: Mutt/1.5.20 (2009-06-14) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201002/91 X-Sequence-Number: 33690 On Wed, Feb 24, 2010 at 02:09:09PM +0100, A. Kretschmer wrote: > 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: Here is a test case I built. I want to list all cruises by cruise_type but after merging cruise_type that have the same cruise_type_name: drop table cruise; drop table cruise_type; create table cruise_type ( id_cruise_type serial primary key, cruise_type_name text ); create table cruise ( id_cruise serial, id_cruise_type integer references cruise_type, cruise_date timestamp default now() ); insert into cruise_type (cruise_type_name) values ('5 day eastern carribean cruise'), ('5 day western carribean cruise'), ('5 day eastern carribean cruise'), ('5 day western carribean cruise') ; insert into cruise (id_cruise_type) values (1), (2), (3), (4), (1), (2), (3), (4) ; select array_agg(ct.id_cruise_type),ct.cruise_type_name from cruise_type ct join cruise c on (c.id_cruise = any(array_agg)) group by cruise_type_name;