If I write

sqlite> CREATE TABLE T1 (N INTEGER CHECK(N >= 0));

the constraint is applied AFTER converting N to an integer.

sqlite> INSERT INTO T1 VALUES('42');
sqlite> INSERT INTO T1 VALUES('-5');
SQL error: constraint failed

But if I write

sqlite> CREATE TABLE T2 (N INTEGER CHECK(TYPEOF(N) = 'integer'));

the constraint is applied BEFORE converting N to an integer.

sqlite> INSERT INTO T2 VALUES(17);
sqlite> INSERT INTO T2 VALUES('18');
SQL error: constraint failed

Why the inconsistency?

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to