v.21.6New Feature

Insert Default Values Instead of NULL in INSERT Queries with insert_null_as_default Option

If insert_null_as_default = 1, insert default values instead of NULL in INSERT ... SELECT and INSERT ... SELECT ... UNION ALL ... queries. Closes #22832. #23524 (Kseniia Sumarokova).
Introduces the insert_null_as_default setting that allows inserting default values instead of NULL in INSERT ... SELECT and INSERT ... SELECT ... UNION ALL ... queries.

Why it matters

This feature addresses cases where users want to avoid inserting NULL values during INSERT ... SELECT operations and prefer default values to be used instead. It improves data consistency and can help prevent issues caused by unexpected NULLs in target tables.

How to use it

Set the setting insert_null_as_default to 1 when executing INSERT ... SELECT or INSERT ... SELECT ... UNION ALL ... queries. For example:

SET insert_null_as_default = 1;
INSERT INTO target_table SELECT * FROM source_table;