Search code examples
sqliteinsertnulldefault-value

SQLite default value if null


Let's say I have a table called "table"

So

Create Table "Table" (a int not null, b int default value 1)

If I do a "INSERT INTO "Table" (a) values (1)". I will get back 1 for column a and 1 for column b as the default value for column b is 1.

BUT if I do "INSERT INTO "Table" (a, b) values (1, null)". I will bet back 1 for column a and an empty value for column b. Is there a way to set a column's default value if a null was given?


Solution

  • No, if you are doing:

    INSERT INTO my_table (a, b) values (1, null) 
    

    You are explicitely asking for a null value on b column.

    In a RDBMS you could technically use a trigger to override that behavior. But in SQLite you can't.