From: | Dawid Kuroczko <qnex42(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Columns into rows. |
Date: | 2005-01-13 10:45:52 |
Message-ID: | 758d5e7f0501130245e2e6fb1@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On Thu, 13 Jan 2005 11:26:04 +0100, Dawid Kuroczko <qnex42(at)gmail(dot)com> wrote:
> I can write:
>
> SELECT * FROM (SELECT id, path AS path_a FROM new_table_paths WHERE id
> = <<NUM>> AND pathtype = 'a') AS a NATURAL FULL OUTER JOIN (SELECT id,
> path AS path_bb FROM new_table_paths WHERE id = <<NUM>> AND pathtype =
> 'bb') AS bb; [ and so on... ]
>
> And its fast; however if I move WHERE id = <<NUM>> outside selects
> (for views), it first "materializes" old layout, and then selects
> id... total waste.
>
> SELECT * FROM (SELECT id, path AS path_a FROM new_table_paths WHERE
> pathtype = 'a') AS a NATURAL FULL OUTER JOIN (SELECT id, path AS
> path_bb FROM new_table_paths WHERE pathtype = 'bb') AS bb WHERE id =
> <<NUM>>;
>
> I wonder if you know other way to write this join so it has good performace?
> Once again, I need a SELECT since I want a VIEW. :-)
Hmm, something like a multiple column returning aggregate...
As far as I know it is not possible to create aggregate which
could return more than one column? I'm thinking about
something like this:
SELECT id,r2c_aggregate(pathtype, path) FROM new_table_paths GROUP BY id;
...where r2c_aggregate(..) would be a plpgsql function doing the
pathtype+path --> path_a = path, path_bb = path2, path_ccc = path3
assembly. And it would be quite efficient I guess! :)
Hmm, r2c_aggregate could return array of arrays of pathtype/path pairs,
which could be processed by other function which would convert them
into rows, but this is UGLY(TM). :)
Regards,
Dawid
From | Date | Subject | |
---|---|---|---|
Next Message | Dawid Kuroczko | 2005-01-13 11:31:20 | Re: Columns into rows. |
Previous Message | Dawid Kuroczko | 2005-01-13 10:26:04 | Columns into rows. |