Click to copy

• Reviewed for ksqlDB 0.29

How to Handle Null Values in ksqlDB

Select

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;

Where

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.

Discover what readers are saying
topictale
Get easy to digest how-tos on ksqlDB
Sign up
Please read our Privacy Policy to understand how we protect and manage your data.
You may also like