From: wstrzalka <wstrzalka@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: ordered by join? ranked aggregate? how to?
Date: Tue, 15 Sep 2009 01:12:59 -0700 (PDT)
Message-ID: <8e3cb4f4-084d-4983-b83a-6efbf6b09308@33g2000vbe.googlegroups.com> (raw)
References: <d7867e26-d5de-4c48-bfac-d6f266b47ec6@l34g2000vba.googlegroups.com>
<20090915075605.GB8046@a-kretschmer.de>
<e7466943-6f25-49fd-82bd-6e4050e59045@p23g2000vbl.googlegroups.com>
On 15 Wrz, 10:10, wstrzalka <wstrza...@gmail.com> wrote:
> On 15 Wrz, 09:56, andreas.kretsch...@schollglas.com ("A. Kretschmer")
> wrote:
>
>
>
> > In response to wstrzalka :
>
> > > What I need is to join 2 tables
>
> > > CREATE TABLE master(
> > > id INT4
> > > );
>
> > > CREATE TABLE slave (
> > > master_id INT4,
> > > rank INT4,
> > > value TEXT);
>
> > > What I need is to make the query:
>
> > > SELECT m.id, array_agg(s.value) AS my_problematic_array
> > > FROM master AS m LEFT JOIN slave AS s ON (m.id = s.master_id)
> > > GROUP BY m.id;
>
> > Faster solution (compared to my other email):
>
> > test=# select id, array_agg(value) from (SELECT m.id, s.value FROM
> > master AS m LEFT JOIN slave AS s ON (m.id = s.master_id) order by 1,2)
> > foo group by 1;
> > id | array_agg
> > ----+-----------
> > 1 | {3,5,7}
> > 2 | {NULL}
> > (2 rows)
>
> > Andreas
> > --
> > Andreas Kretschmer
> > Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
>
> > --
> > Sent via pgsql-sql mailing list (pgsql-...@postgresql.org)
> > To make changes to your subscription:http://www.postgresql.org/mailpref/pgsql-sql
>
> Yes. And No :)
>
> The problem is that in original query the aggregate can be used more
> then once :/
>
> So in fact it's like:
>
> SELECT m.id, array_agg(s1.value), array_agg(s2.value)
> FROM master AS m LEFT JOIN slave AS s1 ON (m.id = s1.master_id AND
> SOME_CONDITION_ON_S1)
> LEFT JOIN slave AS s2 ON (m.id =
> s2.master_id AND SOME_OTHER_CONDITION_ON_S1)
> GROUP BY m.id;
However it still may work as the order by is the same :) Will try ...
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: wstrzalka@gmail.com
Subject: Re: ordered by join? ranked aggregate? how to?
In-Reply-To: <8e3cb4f4-084d-4983-b83a-6efbf6b09308@33g2000vbe.googlegroups.com>
* 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