Jul 21, 2021

ClickHouse tips #10: Null behavior with LowCardinality columns

Does it work? What's actually inserted?
Alejandro del Amo
Data Engineer

If you have LowCardinality(String) column, inserting a NULL value will work fine. It will just treat it like you just have inserted an empty string (‘’). Let’s see an example.

Let’s insert some values now.

And now let’s see what has been inserted. As you can see, even though we inserted a NULL value, internally it’s saved as an empty string.

Bonus: can you create LowCardinality(Nullable(String)) columns?

Yes, you can.

Using LowCardinality(Nullable(String)) instead of Nullable(String), apart of the benefits that it can bring LowCardinality if the conditions are right, also allows you to order by that column. See an example here:

Do you like this post?

Related posts

Real-time Data Visualization: How to build faster dashboards
A new way to create intermediate Data Sources in Tinybird
Tinybird
Team
Jun 15, 2023
Export data from Tinybird to Amazon S3 with the S3 Sink
Tinybird
Team
Mar 21, 2024
Tinybird: A ksqlDB alternative when stateful stream processing isn't enough
To the limits of SQL... and beyond
Automating data workflows with plaintext files and Git
Chatting GraphQL with Jamie Barton of Grafbase
Tinybird
Team
Apr 24, 2023
What it takes to build a real-time recommendation system
We launched an open source ClickHouse Knowledge Base
Tinybird
Team
Oct 11, 2022
The definition of real-time data

Build fast data products, faster.

Try Tinybird and bring your data sources together and enable engineers to build with data in minutes. No credit card required, free to get started.
Need more? Contact sales for Enterprise support.