Type mapping
Overview
Map database types deliberately at application boundaries. SQL NULL becomes None in Python, null in JavaScript; missing fields are a separate concept. Exact decimal amounts and large integers can lose precision when converted to binary floats or JavaScript Number. Use integer minor units or a decimal type as appropriate.
First example
SELECT 9007199254740993, NULL, typeof(9007199254740993);Observed SQLite result (rows in JSON):
[ [ 9007199254740992, null, "integer" ]]How it works
Python sqlite3 decodes INTEGER to int, REAL to float, TEXT to str, BLOB to bytes and NULL to None by default. PostgreSQL numeric and bigint handling depends on the driver; node-postgres may return strings for types without a suitable parser. JavaScript Number has a safe integer bound of 2^53−1; BigInt needs an explicit JSON representation. Distinguish DATE, local timestamp and timestamp with time zone; agree on serialization and precision. SQLite affinity is not PostgreSQL static typing.
Practical example
SELECT SUM(cents), typeof(SUM(cents)) FROM ai_purchase;Observed SQLite result (rows in JSON):
[ [ 2500, "integer" ]]Practice and mistakes
Practice: inspect a large integer and NULL through the driver, then serialize the large integer as a string for a JavaScript consumer. Hint: do not convert monetary cents to float. Check exact integer 9007199254740993 survives in Python. Mistake: replace NULL with zero without a business rule.
PostgreSQL 17 example — NOT RUN
SELECT 9007199254740993::bigint, 12.34::numeric, NULL::text;Expected result, not executed: "Exact bigint and numeric at server; driver representation may differ."