pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dawid Kuroczko <qnex42@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: Columns into rows.
Date: Thu, 13 Jan 2005 11:45:52 +0100
Message-ID: <758d5e7f0501130245e2e6fb1@mail.gmail.com> (raw)
In-Reply-To: <758d5e7f05011302265be7e12a@mail.gmail.com>
References: <758d5e7f05011302265be7e12a@mail.gmail.com>

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



view thread (3+ messages)  latest in thread

Message-ID: <758d5e7f0501130245e2e6fb1@mail.gmail.com>
Permalink:  ../758d5e7f0501130245e2e6fb1@mail.gmail.com/
Also on:    postgresql.org/message-id/758d5e7f0501130245e2e6fb1@mail.gmail.com

 · 

reply

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: qnex42@gmail.com
  Subject: Re: Columns into rows.
  In-Reply-To: <758d5e7f0501130245e2e6fb1@mail.gmail.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