Handle NULL values in queries.
x
(any non-compound data type): A value of any non-compound data type.x
is NULL. (UInt8
)x
is not NULL. (UInt8
)isNull
checks if the special_sauce
column contains NULL values. The result is 1 for the Veggie Delight taco, indicating it has no special sauce.
IS NULL
operator in SQL.x
(Column
): A column.1
if x
allows NULL values. (UInt8
)0
if x
does not allow NULL values. (UInt8
)isNullable
checks whether each column in the taco_orders
table allows NULL values. The special_request
column is defined as Nullable(String)
, so it returns 1
, while the other columns return 0
.
This function is useful for inspecting table schemas and understanding which columns can contain NULL values.
x
: A value of any non-compound data type.x
is not NULL. (UInt8
)x
is NULL. (UInt8
)isNotNull
checks if each taco has a special sauce. The result 1
indicates the presence of a special sauce, while 0
indicates its absence (NULL value).
This function is often used in WHERE
clauses to filter out NULL values or in conditional expressions where NULL handling is important.
See Also:
isNull
functionIS NOT NULL
operatorx
(any type): First JOIN key.y
(any type): Second JOIN key.1
(true) when x
and y
are both NULL or when they are equal.0
(false) otherwise.isNotDistinctFrom
handles various comparisons:
x
(any non-compound data type): The value to check.1
if x
is zero or NULL.0
otherwise.isZeroOrNull
checks if each taco_price
is either zero (free) or NULL (unknown). The result 1
indicates a free taco or unknown price, while 0
indicates a non-zero, known price.
This function is useful for identifying items that are either free or have missing price information in a single operation.
x, ...
: Any number of parameters of non-compound type. All parameters must be of mutually compatible data types.preferred_salsa
is ‘Spicy’, so it’s returned.preferred_salsa
is NULL, so default_salsa
(‘Medium’) is returned.preferred_salsa
and default_salsa
are NULL, so the fallback value ‘Mild’ is returned.x
: The value to check for NULL.alt
: The value that the function returns if x
is NULL.x
if x
is not NULL.alt
if x
is NULL.ifNull
checks if special_instructions
is NULL. If it is, it returns the default text ‘No special instructions’. This is useful for providing default values or handling missing data in taco orders.
x
(Any type): First value to compare.y
(Any type): Second value to compare.x
if the arguments are not equal.nullIf
returns NULL for tacos priced at $5.99, effectively marking them as discounted items. For tacos with different prices, it returns the original price.
x
(Nullable): The original value of Nullable type.assumeNotNull(spice_level)
converts the Nullable spice level to a non-Nullable value.spice_level
was NULL, an arbitrary value (0 in this case) is returned.assumeNotNull
with caution. It’s designed for optimizing performance in cases where you’re certain that a value isn’t NULL. Incorrect use can lead to unexpected results.x
(non-compound type): A value of non-compound type.taco_price
column to a Nullable type. This allows the column to contain NULL values, which can be useful when dealing with missing or unknown prices in the taco menu.
toNullable
function is particularly useful when you need to combine non-Nullable and Nullable columns in operations or when preparing data for joins where one side might contain NULL values.