SQLite does not check Data Types

Viewed 1607

Dear Stack Overflow Community,

I have a little problem here with starting my first attempt to Database-Design.

I try to make some Kind of a tabular and try to check out the Basic functions; writing with Python3 and SQLite3.

My question is quite simple, I have a few lines:

cur.execute('CREATE TABLE IF NOT EXISTS test(a INTEGER, argument DATE)')

Now I can just write:

cur.execute('insert into test (a, argument) values (?,?)', "bla", "blabla")

Without getting an error message; shouldn't this command be automatically forbidden by SQL when you define the allowed datatypes in the CREATE TABLE statement?

Full code is here: http://codepad.org/kf4gZB7m

2 Answers

This feature is Type Affinity:

SQL database engines that use rigid typing will usually try to automatically convert values to the appropriate datatype. The important idea here is that the type is recommended, not required.

Docs: https://sqlite.org/datatype3.html#affinity

Related