There is something wrong with DEFAULT keyword handling
Example:
CREATE TABLE BAR(c1 int null,c2 int default 1 not null)
Executing SQL like this:
INSERT INTO BAR SET c1 = 1, c2 = COALESCE(null,DEFAULT)
Results in:
Column “DEFAULT” not found; SQL statement:
INSERT INTO BAR SET c1 = 1, c2 = COALESCE(null,DEFAULT) [42122-161]
42S22/42122
At the same time:
INSERT INTO BAR (c1,c2) values (1, DEFAULT)
Ok!
But,
INSERT INTO BAR SET c1 = 1, c2 = DEFAULT
Result:
NULL not allowed for column “C2”; SQL statement:
INSERT INTO BAR SET c1 = 1, c2 = DEFAULT [23502-161] 23502/23502
I think it is a bug. If it is not, is any way to specify use of
default value exists?
H2 1.3.161 (2011-10-28)
The term DEFAULT isn’t a pseudo-column or an expression that can be used in a formula. DEFAULT is used instead of an expression. I tried MySQL and it works in the same way as H2.
What you probably want is use a parameterized statement (right?) where NULL is converted to default. H2 does support this, but it’s not fully documented. You can use: