v.20.5New Feature

Add cast_keep_nullable setting for nullable type casting

Add cast_keep_nullable setting. If set CAST(something_nullable AS Type) return Nullable(Type). #11733 (Artem Zuikov).
Introduces the cast_keep_nullable setting that makes CAST(something_nullable AS Type) return Nullable(Type) instead of just Type.

Why it matters

This feature addresses the need to preserve nullability during type casting. When casting a nullable value to another type, users often want to retain the nullable property instead of having it implicitly removed. This setting provides more control and prevents unexpected data loss or errors related to null handling.

How to use it

Enable the feature by setting cast_keep_nullable = 1 in the query or session settings. After enabling, CAST operations on nullable data will preserve the nullable wrapper in the resulting type.