{
  "status": "shipping",
  "advantages": [],
  "limitations": [],
  "supersedes": [],
  "supersededBy": [],
  "firstSeen": null,
  "lastSeen": null,
  "updated": "2026-11-21",
  "slug": "sqlite-type-affinity",
  "term": "SQLite type affinity",
  "aliases": [
    "column affinity"
  ],
  "definition": "SQLite type affinity is a column's preference for a storage class, which can cause values to be converted when inserted or compared.",
  "note": "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. [affinity]\n\nIn 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. [experiment]\n\nAfter 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. [sum-contract] [sum-evidence] [sum-replay]",
  "related": [
    "sqlite-strict-table",
    "sqlite-integrity-check",
    "sqlite-online-backup",
    "csv"
  ],
  "citations": [
    {
      "id": "affinity",
      "title": "SQLite: Datatypes, numeric affinity and storage classes",
      "url": "https://www.sqlite.org/datatype3.html",
      "accessed": "2026-10-20"
    },
    {
      "id": "experiment",
      "title": "Hesela: SQLite import precision experiment",
      "url": "https://hesela.com/analyses/sqlite-import-numeric-precision/",
      "accessed": "2026-10-20"
    },
    {
      "id": "sum-contract",
      "title": "SQLite: SUM, TOTAL and aggregate input ordering",
      "url": "https://www.sqlite.org/lang_aggfunc.html",
      "accessed": "2026-11-07"
    },
    {
      "id": "sum-evidence",
      "title": "Hesela: SQLite sum-order observations and exact bounds",
      "url": "https://hesela.dev/research/sqlite-sum-order/summary.json",
      "accessed": "2026-11-07"
    },
    {
      "id": "sum-replay",
      "title": "Hesela: SQLite sum-order code, observations and replay tests",
      "url": "https://hesela.dev/research/sqlite-sum-order/package.zip",
      "accessed": "2026-11-07"
    }
  ],
  "provenance": [
    "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. [sum-evidence]"
  ]
}
