Re: CASE WHEN idiomatic for functions with side-effect?

2021-01-12 Thread Joel Jacobson
Many thanks Tom and David for clarifying the semantics. /Joel

Re: CASE WHEN idiomatic for functions with side-effect?

2021-01-12 Thread Tom Lane
"Joel Jacobson" 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

Re: CASE WHEN idiomatic for functions with side-effect?

2021-01-12 Thread David G. Johnston
On Tue, Jan 12, 2021 at 1:14 AM Joel Jacobson wrote: > Is it idiomatic and safe to use > > SELECT > CASE boolean_expression WHEN TRUE THEN function_with_side_effects() END > As long as function_with_side_effects() is defined volatile it is forced to be executed at runtime, once per row. That

CASE WHEN idiomatic for functions with side-effect?

2021-01-12 Thread Joel Jacobson
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? function_with_side_effects() is known to be a normal function, and not an