Re: Columns into rows. - Mailing list pgsql-sql

From Dawid Kuroczko
Subject Re: Columns into rows.
Date
Msg-id 758d5e7f0501130245e2e6fb1@mail.gmail.com
Whole thread Raw
In response to Columns into rows.  (Dawid Kuroczko <qnex42@gmail.com>)
Responses Re: Columns into rows.
List pgsql-sql
On Thu, 13 Jan 2005 11:26:04 +0100, Dawid Kuroczko <qnex42@gmail.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


pgsql-sql by date:

Previous
From: Dawid Kuroczko
Date:
Subject: Columns into rows.
Next
From: Dawid Kuroczko
Date:
Subject: Re: Columns into rows.