CASE WHEN
Evaluates conditions in order and returns the value for the first one that is true, with an optional ELSE fallback. Syntaxcondition— a boolean expression tested in order.result— value returned when its WHEN condition is the first true one.default— value returned when no condition matches; NULL if the ELSE branch is omitted.
- The result of the first matching branch, otherwise the ELSE value (or NULL).
Bucket users by lifetime value
coalesce
Returns the first non-NULL argument, evaluating them left to right. Syntaxexpr1, expr2, ...— one or more expressions of compatible types.
- The first non-NULL argument, or NULL if every argument is NULL.
Fall back to a default plan
if
Returns one of two values depending on a boolean condition. Syntaxcondition— a boolean expression.then— value returned whenconditionis true.else— value returned whenconditionis false.
thenwhenconditionis true, otherwiseelse.
Flag high-value users
multiIf
Evaluates condition/value pairs in order and returns the value for the first true condition, with a final default. A compact alternative to CASE WHEN. Syntaxcondition1, condition2, ...— boolean expressions tested in order.value1, value2, ...— value returned for the corresponding condition.default— value returned when no condition is true.
- The value of the first true condition, otherwise
default.
Bucket users by lifetime value
transform
Maps a value against parallel “from” and “to” arrays — an inline lookup table. If the value isn’t found, it returns the default (4-argument form) or the value unchanged (3-argument form). Syntaxexpr— the value to map.from_array— array of source values to matchexpragainst.to_array— array of replacement values, matched by position tofrom_array.default— value returned whenexprmatches nothing. Omit it (3-argument form) to returnexprunchanged on no match.
- The mapped value, or the default / original value when there’s no match.
Users whose plan maps to a paid tier
nullif
Returns NULL when the two arguments are equal, otherwise returns the first argument. Handy for guarding against division by zero or blanking sentinel values. Syntaxexpr1— the value returned when the two differ.expr2— the value compared againstexpr1.
- NULL when
expr1 = expr2, otherwiseexpr1.
Blank out empty plan strings
:: (cast)
Converts a value from one data type to another.:: is the PostgreSQL-style cast operator; CAST(expr AS type) is the equivalent standard SQL form.
Syntax
expr— the value or expression to convert.type— the target data type, for exampleDOUBLE PRECISION,INTEGER, orTEXT.
exprconverted totype. Returns NULL whenexpris NULL.
Cast JSON properties with both forms
ifnull
Returns the first argument if it is not NULL, otherwise the second. Equivalent to a two-argumentcoalesce.
Syntax
expr— the expression to test.alt— value returned whenexpris NULL.
exprwhen it is non-NULL, otherwisealt.
Default a missing plan to free
assumeNotNull
Tells the query engine that an expression is never NULL, turning a nullable type into a non-nullable one. Use it only when you are certain no NULLs are present. Syntaxexpr— a possibly-nullable expression.
- The same value with a non-nullable type. Behavior is undefined if
expris actually NULL.
Treat a filtered column as non-null
toNullable
Converts an expression to a nullable type without changing its value. The inverse ofassumeNotNull.
Syntax
expr— any expression.
- The same value carried in a nullable type.
Make a column nullable
xor
Logical exclusive OR. Returns true when exactly one of the two boolean arguments is true. Syntaxa— a boolean expression.b— a boolean expression.
- Boolean true when exactly one of
aandbis true, otherwise false.
Users on trial or with spend, but not both