Skip to main content
Scalar function
A NULL condition selects false_value. A NULL selected branch produces NULL.

Syntax

Scalar

  • All result alternatives must have compatible types. Matching types are preserved; mixed types may be converted to a common type. Use explicit casts to choose the result type.

Arguments

Returns

  • Type: Common SQL type after conversion of true_value and false_value
  • NULL behavior: A NULL condition selects false_value. A NULL selected branch produces NULL.

Properties

Usage notes

  • The two result branches must have compatible types. They are converted to a common type when needed.
  • INTEGER and INT mean the same type; STRING means VARCHAR text. NULL can be used with a supported type. Cast NULL explicitly when its type would otherwise be unclear.
  • Query tools may report a DECIMAL result as DOUBLE or a TIME result as INTEGER. The returned value still keeps its decimal precision and scale, or its time type. A reported type does not convert the value.
  • Deterministic: The same inputs and settings produce the same result.

Examples

Typical behavior

Choose between string results

Last modified on October 15, 2026