| От | Tom Lane |
|---|---|
| Тема | Re: CASE WHEN idiomatic for functions with side-effect? |
| Дата | |
| Msg-id | 1126920.1610462907@sss.pgh.pa.us обсуждение исходный текст |
| Ответ на | CASE WHEN idiomatic for functions with side-effect? ("Joel Jacobson" <joel@compiler.org>) |
| Ответы |
Re: CASE WHEN idiomatic for functions with side-effect?
|
| Список | pgsql-general |
"Joel Jacobson" <joel@compiler.org> writes:
> Is it idiomatic and safe to use
> SELECT
> CASE boolean_expression WHEN TRUE THEN function_with_side_effects() END
> in a query to ensure the function_with_side_effects() is only
> execute if boolean_expression is true?
As long as function_with_side_effects() is properly marked volatile,
it's safe (whether it's idiomatic is in the eye of the beholder).
The issue with the divide-by-zero example is that the division operator
is marked immutable, so if the planner sees that it has constant arguments
it will try to simplify-on-sight, even within a CASE expression.
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера