Reputation: 424
I want to implement mySQL IF function equivalent in Redshift using User Defined Function in Redshift.The syntax would be:
IF(condition, value_if_true, value_if_false)
Is it possible to pass the condition/expression to Redshift UDF's?
Upvotes: 1
Views: 325
Reputation: 4354
You cannot pass an expression to a UDF but you can pass a string. which you could then evaluate in python.
However, the easier way is to use the case statement
case {condition} then {value_if_true} else {value_if_false} end
the case statement is a standard in SQL (wheras IF is not)
https://docs.aws.amazon.com/redshift/latest/dg/r_CASE_function.html
Upvotes: 1