Re: Reuse temporary calculation results in an SQL update query [SOLVDED]

Поиск
Список
Период
Сортировка
От David Johnston
Тема Re: Reuse temporary calculation results in an SQL update query [SOLVDED]
Дата
Msg-id 005e01cd9f28$481c39d0$d854ad70$@yahoo.com
обсуждение исходный текст
Ответ на Re: Reuse temporary calculation results in an SQL update query [SOLVDED]  (Matthias Nagel <matthias.h.nagel@gmail.com>)
Список pgsql-sql
>
> thank you. The "WITH" clause did the trick. I did not even know that such a
> thing exists. But as it turns out it makes the statement more readable and
> elegant but not faster.
>
> The reason for the latter is that both the CTE and the UPDATE statement
> have the same "FROM ... WHERE ..." part, because the tempory calculation
> needs some input values from the same table. Hence the table is looked up
> twice instead once.

This is unusual; the only WHERE clause you should require is some kind of key matching...

Like:

UPDATE tbl
SET ....
FROM (
WITH final_result AS (SELECT pkid, ....FROM tblWHERE ...
) -- /WITH
SELECT pkid, .... FROM final_result
) src  -- /FROM
WHERE src.pkid = tbl.pkid
;

If you provide an actual query better help may be provided.

David J.






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

Предыдущее
От: Johnny Winn
Дата:
Сообщение: Re: Need help with a special JOIN
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: HOw to convert unicode to string