Re: Reuse temporary calculation results in an SQL update query [SOLVDED]
В списке pgsql-sql по дате отправления:
| От | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера