sqlite-type-affinity · shipping · also column affinity

SQLite type affinity

SQLite type affinity is a column's preference for a storage class, which can cause values to be converted when inserted or compared.

Related Observatory article: Read on hesela.com

Numeric affinity can convert numeric-looking text to INTEGER or REAL. The declared column type and the actual storage class are separate properties. Preserve a source representation when its exact spelling or decimal value matters. [1]

In a controlled SQLite 3.45.1 matrix, text 9007199254740993.0 became integer 9007199254740992 in NUMERIC and STRICT INTEGER columns, while the digit-only string and exact integer binding preserved the intended integer. Completed backup and integrity checks retained the converted values. [2]

After conversion: exact INTEGER storage does not guarantee an exact aggregate. In two controlled builds, summing 9223372036854775807, 1 and -1 either overflowed or succeeded as index order changed. TOTAL avoided the error but rounded the result up by one. Nonnegative INTEGER inputs whose exact total fits the signed 64-bit range cannot overflow an intermediate sum, in any order. Signed corrections need separate positive and negative subtotal bounds computed with wider exact arithmetic. [3] [4] [5]

Relations

related
SQLite STRICT table, SQLite integrity_check, SQLite Online Backup API, Comma-separated values (CSV)

Citations

  1. SQLite: Datatypes, numeric affinity and storage classes (accessed 2026-10-20)
  2. Hesela: SQLite import precision experiment (accessed 2026-10-20)
  3. SQLite: SUM, TOTAL and aggregate input ordering (accessed 2026-11-07)
  4. Hesela: SQLite sum-order observations and exact bounds (accessed 2026-11-07)
  5. Hesela: SQLite sum-order code, observations and replay tests (accessed 2026-11-07)
Sources & caveats
  • Definition from SQLite documentation; observations from 75 designed insert attempts, not a population study.
  • The aggregation supplement uses SQLite 3.45.1 and 3.53.1 with different environments. The designed boundary example is not a version-effect experiment or a rate estimate; index choice is not guaranteed. [4]

JSON: /data/terms/sqlite-type-affinity.json

Published by Hesela team · Updated

Report a correction · Editorial standards · Reuse guidance

Cite this page
Hesela team. SQLite type affinity. Hesela. 2026-11-21. https://hesela.dev/terms/sqlite-type-affinity/