Posts

Showing posts with the label python sql

NULL vs None in sqlite3 for Python

Null vs None in sqlite3, Python The sqlite3 library in Python accepts Python data types for data insertion. This table in the docs shows the type conversion for data when transferred between SQLite and Python. NULL vs None SQLite automatically accepts NULL (and null ) since it is a reserved keyword in. It cannot, however, be accepted as input via parameter substitution. We build a database and explain the distinctions in the following gist: dbpath = "/.../test.db" >>> import sqlite3 >>> connection = sqlite3.connect(dbpath) >>> cursor = connection.cursor() >>> cursor.execute("CREATE TABLE Test (testcolumn TEXT);") >>> cursor.execute("INSERT INTO Test VALUES(NULL);") >>> #We now have exactly one entry in our table. Verify this with SELECT: >>> cursor.execute("SELECT * FROM Test WHERE testcolumn IS NULL;") >>> for item in cursor: print(item) (Non