Click to copy
Functions And Operators • Reviewed for ksqlDB 0.29
How to Handle Null Values in ksqlDB
To handle null values in ksqldb, you can use the COALESCE function. This function returns the first non-null value in a list of values. For example, you could use it like this:
SELECT COALESCE(category, subcategory, 'general')
FROM products;
This would return 'general' for any rows in products
where category
is null, and the actual value of category
for all other rows.
You can also use the IFNULL function, which is similar to COALESCE but accepts only one default value instead of a list of defaults.
SELECT IFNULL(category, 'general')
FROM products;
Alternatively, you can use the IS NOT NULL operator in a WHERE clause to filter out rows with null values.
SELECT *
FROM products
WHERE category IS NOT NULL;
This would return all rows from products
where category
is not null.
Was this article helpful?