postgresql_16:3.6.18.3 NULLIF
PostgreSQL 16 > The SQL Language > Functions and Operators > Conditional Expressions > NULLIF
NULLIF(value1, value2)
The NULLIF function returns a null value if *value1* equals *value2*; otherwise it returns *value1*. This can be used to perform the inverse operation of the COALESCE example given above: SELECT NULLIF(value, '(none)') ... In this example, if value is (none), null is returned, otherwise the value of value is returned.
The two arguments must be of comparable types. To be specific, they are compared exactly as if you had written *value1* = *value2*, so there must be a suitable = operator available.
The result has the same type as the first argument — but there is a subtlety. What is actually returned is the first argument of the implied = operator, and in some cases that will have been promoted to match the second argument's type. For example, NULLIF(1, 2.2) yields numeric, because there is no integer = numeric operator, only numeric = numeric.