Re: Reuse temporary calculation results in an SQL update query

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Reuse temporary calculation results in an SQL update query
Дата
Msg-id B638A88E-32D8-455E-9224-C5708D5F2585@yahoo.com
обсуждение исходный текст
Ответ на Reuse temporary calculation results in an SQL update query  (Matthias Nagel <matthias.h.nagel@gmail.com>)
Список pgsql-sql
On Sep 29, 2012, at 6:49, Matthias Nagel <matthias.h.nagel@gmail.com> wrote:

> Hello,
>
> is there any way how one can store the result of a time-consuming calculation if this result is needed more than once
inan SQL update query? This solution might be PostgreSQL specific and not standard SQL compliant. Here is an example of
whatI want: 
>
> UPDATE table1 SET
>   StartTime = 'time consuming calculation 1',
>   StopTime = 'time consuming calculation 2',
>   Duration = 'time consuming calculation 2' - 'time consuming calculation 1'
> WHERE foo;
>
> It would be nice, if I could use the "new" start and stop time to calculate the duration time. First of all it would
makethe SQL statement faster and secondly much more cleaner and easily to understand. 
>
> Best regards, Matthias
>
>

You are allowed to use a FROM clause with UPDATE so if you can figure out how to write a SELECT query, including a CTE
ifneeded, you can use that as your cache. 

An immutable function should also be optimized in theory though I've never tried it.

David J.




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

Предыдущее
От: Matthias Nagel
Дата:
Сообщение: Re: Reuse temporary calculation results in an SQL update query
Следующее
От: Thomas Kellerer
Дата:
Сообщение: Re: Reuse temporary calculation results in an SQL update query