Maksim Dmitriev
Maksim Dmitriev

Reputation: 6209

SQLite. Column constraint CHECK doesn't work with an INTEGER column

I tested the following cases.

CHECK is applied to an INTEGER column. It doesn't work.

sqlite> CREATE TABLE log (_id INTEGER PRIMARY KEY, timestamp INTEGER NOT NULL, message TEXT NOT NULL, status INTEGER NOT NULL CHECK (status IN (1, 0));
Error: near ";": syntax error

CHECK is applied to a TEXT column. It works.

sqlite> CREATE TABLE log (_id INTEGER PRIMARY KEY, timestamp INTEGER NOT NULL, message TEXT NOT NULL CHECK (message IN ('Bad', 'OK')), status INTEGER NOT NULL);
sqlite> insert into log values (3, 11111, 'OK', 1); 
sqlite> select * from log;
3|11111|OK|1
sqlite> insert into log values (3, 11111, 'dsvsdvOK', 1); 
Error: constraint failed

Both cases should work if I understand the documentation correctly.

column-constraint

expr

Upvotes: 0

Views: 173

Answers (1)

CL.
CL.

Reputation: 180060

The first CREATE TABLE statement has three opening but only two closing parentheses.

Upvotes: 2

Related Questions