Skip to main content
Evaluates a condition and returns different results based on whether the condition is true or false. The IF function is a simplified alternative to the CASE expression for handling conditional logic.

Syntax

Parameters

Return type

The IF function returns the common data type of the <then> and <else> parameters. Both parameters are cast to this type. For example, IF(false, 1, 2.5) returns a DOUBLE PRECISION. The function fails if the two types have no common type.

Example

The following example classifies each level in the levels table as 'Hard' when its maxpoints score threshold is 100 or above, and 'Easy' otherwise:

Rows: 10Execution time: 6.00ms