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