v.21.6New Feature
Insert Default Values Instead of NULL in INSERT Queries with insert_null_as_default Option
Ifinsert_null_as_default= 1, insert default values instead of NULL inINSERT ... SELECTandINSERT ... SELECT ... UNION ALL ...queries. Closes #22832. #23524 (Kseniia Sumarokova).
Why it matters
This feature addresses cases where users want to avoid inserting NULL values duringINSERT ... 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 settinginsert_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;