The data type of a value can be determined with typeof(val).
The following simple select statement selects the type of the five values, each with one of the possible types:
.mode column
.width 10 10 10 10 10
.header on
select
typeof( 42 ) i,
typeof( 99.9 ) r,
typeof('string' ) t,
typeof( null ) n,
typeof( x'deadbeef') b
;
--
-- i r t n b
-- ---------- ---------- ---------- ---------- ----------
-- integer real text null blob
--
SQlite version 3.37.0 introduced strict tables. Such tables only allow values that adhere to the defined data types in the table.
Ordering values
When values are ordered with an order by clause, the data type determines the first level of ordering: first are nulls, then numerical values (integer and real), then text and finally blobs.
int-range.py
import sqlite3
import math
import os.path
db_file = 'int-range.db'
if os.path.isfile(db_file):
os.remove(db_file)
db = sqlite3.connect(db_file)
cur = db.cursor()
cur.execute('create table int_range(i int, ii int)')
for i in range(0, 63): # 64 would result in «OverflowError: Python int too large to convert to SQLite INTEGER»
cur.execute ('insert into int_range values (?, ?)', ( i, 2**i))
for i in range(0, 63):
for r in cur.execute('select ii from int_range where i = ?', (i, )):
print math.log(r[0], 2)