Re: Doing multiple steps at once

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Doing multiple steps at once
Дата
Msg-id 18798.1046628609@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Doing multiple steps at once  (Detlef Jockheck <detlef@jockheck.de>)
Список 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 по дате отправления:

Предыдущее
От: Justin Clift
Дата:
Сообщение: Ok, we just need 26 more votes to win this award....
Следующее
От: "Ben-Nes Michael"
Дата:
Сообщение: function problem plpgsql