🚀
Introducing Versions: Develop data products using Git. Join the waitlist

ClickHouse tips #10: Null behavior with LowCardinality columns

Does it work? What's actually inserted?
Alejandro del Amo
Data Engineer
Jul 21, 2021
 ・ 
  min read

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 {% code-line %}LowCardinality(Nullable(String)){% code-line-end %} instead of {% code-line %}Nullable(String){% code-line-end %}, apart of the benefits that it can bring {% code-line %}LowCardinality{% code-line-end %} if the conditions are right, also allows you to order by that column. See an example here: