Declaration
IF(expr1, expr2)
IF(expr1, expr2, expr3)
Description
If the value of expr1 is TRUE (that is, expr1<>0 and expr1<>NULL), the result is expr2; otherwise:
- When using the two-argument form
IF(expr1, expr2), returnsNULL. - When using the three-argument form
IF(expr1, expr2, expr3), returnsexpr3.
The result of IF() can be a numeric or string type, depending on the content used.
If only one of expr2 and expr3 is explicitly NULL, the result type of the IF() function is the result type of the non-NULL expression.
Examples
obclient> SELECT IF(5>6, 'T','F'), IF (5>6, 1, 0), IF(NULL, 'TRUE', 'FALSE'), IF(0, 'TRUE', 'FALSE')\G
*************************** 1. row ***************************
IF(5>6, 'T','F'): F
IF (5>6, 1, 0): 0
IF(NULL, 'TRUE', 'FALSE'): FALSE
IF(0, 'TRUE', 'FALSE'): FALSE
1 row in set