Functions for Working with Nullable Values
isNull
Returns whether the argument is NULL.
See also operator IS NULL.
Syntax
Alias: ISNULL.
Arguments
x— A value of non-compound data type.
Returned value
1ifxisNULL.0ifxis notNULL.
Example
Table:
Query:
Result:
isNullable
Returns 1 if a column is Nullable (i.e allows NULL values), 0 otherwise.
Syntax
Arguments
x— column.
Returned value
Example
Query:
Result:
isNotNull
Returns whether the argument is not NULL.
See also operator IS NOT NULL.
Arguments:
x— A value of non-compound data type.
Returned value
1ifxis notNULL.0ifxisNULL.
Example
Table:
Query:
Result:
isNotDistinctFrom
Performs null-safe comparison. Used to compare JOIN keys which contain NULL values in the JOIN ON section.
This function will consider two NULL values as identical and will return true, which is distinct from the usual
equals behavior where comparing two NULL values would return NULL.
This function is an internal function used by the implementation of JOIN ON. Please do not use it manually in queries.
Syntax
Arguments
x— first JOIN key.y— second JOIN key.
Returned value
truewhenxandyare bothNULL.falseotherwise.
Example
For a complete example see: NULL values in JOIN keys.
isZeroOrNull
Returns whether the argument is 0 (zero) or NULL.
Arguments:
x— A value of non-compound data type.
Returned value
1ifxis 0 (zero) orNULL.0else.
Example
Table:
Query:
Result:
coalesce
Returns the leftmost non-NULL argument.
Arguments:
- Any number of parameters of non-compound type. All parameters must be of mutually compatible data types.
Returned values
- The first non-
NULLargument NULL, if all arguments areNULL.
Example
Consider a list of contacts that may specify multiple ways to contact a customer.
The mail and phone fields are of type String, but the telegram field is UInt32, so it needs to be converted to String.
Get the first available contact method for the customer from the contact list:
ifNull
Returns an alternative value if the argument is NULL.
Arguments:
x— The value to check forNULL.alt— The value that the function returns ifxisNULL.
Returned values
xifxis notNULL.altifxisNULL.
Example
Query:
Result:
Query:
Result:
nullIf
Returns NULL if both arguments are equal.
Arguments:
x, y — Values to compare. Must be of compatible types.
Returned values
NULLif the arguments are equal.xif the arguments are not equal.
Example
Query:
Result:
Query:
Result:
assumeNotNull
Returns the corresponding non-Nullable value for a value of Nullable type. If the original value is NULL, an arbitrary result can be returned. See also functions ifNull and coalesce.
Arguments:
x— The original value.
Returned values
- The input value as non-
Nullabletype, if it is notNULL. - An arbitrary value, if the input value is
NULL.
Example
Table:
Query:
Result:
Query:
Result:
toNullable
Converts the argument type to Nullable.
Arguments:
x— A value of non-compound type.
Returned value
- The input value but of
Nullabletype.
Example
Query:
Result:
Query:
Result: