From: A. Kretschmer <andreas.kretschmer@schollglas.com>
To: pgsql-sql@postgresql.org
Subject: Re: join with an array
Date: Wed, 24 Feb 2010 14:09:09 +0100
Message-ID: <20100224130909.GL22249@a-kretschmer.de> (raw)
In-Reply-To: <20100224124023.GA16500@apartia.fr>
References: <20100224124023.GA16500@apartia.fr>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: andreas.kretschmer@schollglas.com
Subject: Re: join with an array
In-Reply-To: <20100224130909.GL22249@a-kretschmer.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox