Re: Doing multiple steps at once - Mailing list pgsql-general

From Tom Lane
Subject Re: Doing multiple steps at once
Date
Msg-id 18798.1046628609@sss.pgh.pa.us
Whole thread Raw
In response to Doing multiple steps at once  (Detlef Jockheck <detlef@jockheck.de>)
List pgsql-general
Detlef Jockheck <detlef@jockheck.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

pgsql-general by date:

Previous
From: Justin Clift
Date:
Subject: Ok, we just need 26 more votes to win this award....
Next
From: "Ben-Nes Michael"
Date:
Subject: function problem plpgsql