One of SQLite‘s non-standard extensions to SQL is the ON CONFLICT
clause.
This clause allows you to determine what should happen when certain conflicts occur due to a constraint violation.
One of the things you can use this clause for is to replace NULL
values with a column’s default value when inserting or updating data in a table.
By default, if you try to explicitly insert NULL
into a column with a NOT NULL
constraint, it will fail.
And if you try to explicitly insert NULL
into a column without a NOT NULL
constraint, then NULL
will be assigned to that column, even if there’s a DEFAULT
clause.
However, you can use the ON CONFLICT
clause to set it to the default value instead of NULL
.
Continue reading →