Re: execute same query only one time?

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: execute same query only one time?
Дата
Msg-id CAKFQuwYNx467yxk62C=JZaaadqETJHCGMRgLOCwxiW6FDN3Xpg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: execute same query only one time?  (Marc Mamin <M.Mamin@intershop.de>)
Список pgsql-general
On Tue, Feb 9, 2016 at 12:16 PM, Marc Mamin <M.Mamin@intershop.de> wrote:

>>>> Hi,
>>>>
>>>> is there a best practice to share data between two select statements?

Hi,
I didn't check the whole thread so forgive me if this was already proposed,
but maybe you could do something like:

create temp table result2 (...)

query_1:
WITH cte as (select ..),
tmp as ( INSERT INTO result2 select ...  from cte),
SELECT ... from cte;

query_2:
select * from result2;

​It was, more or less.  I'm not sure you buy much using an updating CTE in lieu of a dedicated statement populating the temporary table.  It seems a bit more confusing to comprehend and the performance benefit has to be marginal given we expect to only insert a single row into the temp table.

David J.
 

В списке pgsql-general по дате отправления:

Предыдущее
От: Marc Mamin
Дата:
Сообщение: Re: execute same query only one time?
Следующее
От: Vitaly Burovoy
Дата:
Сообщение: Re: execute same query only one time?