Re: Doing multiple steps at once

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Detlef Jockheck <detlef(at)jockheck(dot)de>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Doing multiple steps at once
Date: 2003-03-02 18:10:09
Message-ID: 18798.1046628609@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Detlef Jockheck <detlef(at)jockheck(dot)de> writes:
> 1st: I create/clear a temporary table c
> 2nd: doing a "insert into c select something from a"
> 3rd: doing a "insert into c select something from b"
> 4th: calculate a result with "select something from c group by column"

> Is it possible to do the four steps (1-4) at once (with a function, procedure
> or so?)

Do you need a temp table at all? The given calculation could be done
with something like

SELECT whatever
FROM (SELECT something FROM a
UNION ALL
SELECT something FROM b) ss
GROUP BY column

I can't see a need for a temp table unless your intention is to scan the
UNION result multiple times, in which case building the temp table might
be faster than repeating the UNION.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ben-Nes Michael 2003-03-02 18:30:09 function problem plpgsql
Previous Message Justin Clift 2003-03-02 17:44:49 Ok, we just need 26 more votes to win this award....