Research notes / Data preservation
SQLite imports: where exact identifiers lose digits
Published 20 October 2026 / Updated 2026-11-22 / Controlled software experiments
An import can change an identifier before a backup ever sees it. In SQLite 3.45.1, the text 9007199254740993.0 became 9007199254740992 in a STRICT INTEGER column. The database and its completed backup both passed integrity checks.
On this page13 sections
One numeric value, different import paths
We crossed five source strings with three parameter types and five schemas: 75 deliberately chosen insert attempts. An independent Python Decimal comparison checked exact numeric equality; a separate check compared original spelling. Every result below was read after closing and reopening the database, not from the insert's return value.
| Source text | Bound as / column | Stored value / type | Exact numeric value? |
|---|---|---|---|
9007199254740993 | Text parameter STRICT INTEGER | 9007199254740993integer | Yes |
9007199254740993.0 | Text parameter STRICT INTEGER | 9007199254740992integer | No |
9007199254740993.0 | Exact integer STRICT INTEGER | 9007199254740993integer | Yes |
9007199254740993.0 | Text parameter STRICT ANY | 9007199254740993.0text | Yes |
9007199254740993 | Python float STRICT ANY | 9007199254740992.0real | No |
00123 | Text parameter Ordinary ANY | 123integer | Yes |
00123 | Text parameter STRICT ANY | 00123text | Yes |
The plain digit string preserved the large integer. Adding .0 changed the conversion path. Parsing that decimal exactly into a Python integer before binding preserved the value as well. The parser in our harness first requires a finite integral value within SQLite's signed 64-bit range; it does not truncate fractions.
These are not failure-rate samples. The complete matrix includes scientific notation, leading zeros and 9223372036854775807, the signed 64-bit maximum. Of 75 attempts, 74 were accepted and one was rejected. Twenty-five accepted values differed numerically from their source strings under the exact oracle.
Three conversion boundaries to keep separate
Before binding: Python maps str, int and float to SQLite TEXT, INTEGER and REAL parameters. A float created from 9007199254740993 already represents 9007199254740992. No column can infer the discarded digit. The JSON records the bound type, decimal value and float hexadecimal representation. [6]
During affinity conversion: SQLite's type affinity can turn text into a number. Binary64 cannot represent every integer at this magnitude. This is different from SQLite INTEGER, which can preserve signed 64-bit integers exactly. [2] [3]
During strict validation: STRICT enforces accepted storage types but still applies conversion rules. In the pinned 3.45.1 source, OP_TypeCheck applies affinity before testing the resulting type. applyNumericAffinity can produce a real value and then try an integer conversion. That latter check compares the already represented real value with an integer, not with an arbitrary-precision copy of the source decimal. [4] [5]
The documentation describes lossless coercion. Our measured decimal-point example shows why that wording must not be read as a promise to preserve every digit of arbitrary decimal input. This result is scoped to the recorded runtime; it is not a new vulnerability claim or a test of every release. [1]
Sorting can lose a record without changing its digits
Correct text storage cannot preserve a record that preprocessing already removed. On GNU Coreutils 9.4, sort -g -u reduced the distinct integers 18446744073709551616 and 18446744073709551617 to one unchanged line. Exit status was zero, with no diagnostic. Binding that survivor as SQLite TEXT preserved it exactly; integrity_check returned ok.
The pinned upstream implementation uses strtold for general numeric comparison. Our separate compiled C probe measured a 64-bit significand for long double; both tokens were completely consumed and converted to the same value, without a conversion error. That is not the familiar binary64 boundary: the 2^53 control retained both lines. A 16-byte storage size does not mean 128 bits of significand precision. [14] [16]
Why does the boundary move? Goldberg describes precision as the number of significand digits, separate from the exponent range. For a normalized binary format with p significant bits, adjacent values in [2^e, 2^(e+1)) are spaced by 2^(e-p+1). Applying that representation to our measured p = 64 gives 2^(64-64+1) = 2 immediately above 2^64, so 2^64 + 1 is not representable. This is a mathematical explanation of the captured boundary, not another experiment or a universal promise about long double. [17]
| Input fixture | Input lines | -n -u | -g -u | Complete-line -u |
|---|---|---|---|---|
| 2^53 and 2^53+1 | 2 | 2 | 2 | 2 |
| 2^64-2 and 2^64-1 | 2 | 2 | 2 | 2 |
| 2^64 and 2^64+1 | 2 | 2 | 1 | 2 |
| 2^100 and 2^100+1 | 2 | 2 | 1 | 2 |
| 1e0 / 1e1 | 2 | 1 | 2 | 2 |
| 0 / +1 | 2 | 1 | 2 | 2 |
| 7 drive-A / 7 drive-B | 2 | 1 | 1 | 2 |
| missing / unavailable | 2 | 1 | 1 | 2 |
| 001 / 1 | 2 | 1 | 1 | 2 |
| 7 drive-A / 7 drive-B / 7 drive-A | 3 | 1 | 1 | 2 |
Three mechanisms must stay separate: approximate comparison can merge different numbers; a narrower grammar can misread a token; and numeric equality can intentionally ignore a record's remaining fields. GNU documents exact decimal comparison for -n, but not exponent notation or a leading plus. Replacing -g with -n is therefore not a general repair. [13]
Likewise, stable sorting is not complete-record deduplication. With 7 drive-A, 7 drive-B, 7 drive-A, sort -g -s followed by uniq retained all three lines: equal numeric keys kept identical records apart. The ordinary sort -g followed by uniq retained two; sort -g -u retained one. The intended identity rule determines which result is appropriate.
The smartctl verbose JSON option provides string companions for potentially unsafe integers and byte arrays for values potentially beyond 64 bits. That protects a producer-side representation, not a later approximate comparator. We tested constructed strings, not smartctl or physical drives. [15]
Every one of the 60 paths passed its matching sortedness check and SQLite integrity check. Neither checks completeness against the input. Define whether equality means source bytes, an exact number or a device/sample key, then compare the resulting set or multiset with the retained source. Plain sort -u preserved distinct complete lines in this ASCII, LF-delimited, C-locale fixture; this is not a recipe for quoted multiline CSV, binary records or other collations. [13] [7]
A valid type can still be the wrong identifier
ANY has different semantics in ordinary and STRICT tables. In our ordinary table, text 00123 became integer 123. STRICT ANY preserved the received string. That distinction matters when leading zeros are part of an identifier rather than formatting for a number. [1]
A two-input control inserted 9007199254740992.0 and 9007199254740993.0 as text into a STRICT INTEGER UNIQUE column. The first succeeded; the second hit SQLITE_CONSTRAINT_UNIQUE (2067). Both texts remained distinct in the corresponding STRICT ANY table. We used plain INSERT, not IGNORE or REPLACE, and retained the explicit error. [8]
STRICT still rejected the separate text inputs 1.5 and abc for INTEGER, with extended code 3091. The tested Python wrapper reported the symbolic name as unknown; evidence retains that raw name and the numeric code. A missing wrapper label is not an unknown database outcome. [8]
The backup faithfully retained the import
After closing the writer, we opened the source read-only and completed Python's SQLite backup API. Its last progress callback reported SQLITE_DONE with zero remaining pages. After reopening the destination, every matrix row, storage class and collision-control row matched the source. Its changed numbers were still changed. The source SHA-256 was identical before and after observation. [6]
Both quick_check and integrity_check returned ok for source and destination. Such checks inspect database consistency, not equality with an external import file. A successful copy is useful evidence about the copy; it cannot restore information discarded before storage. [7]
This complements the existing SQLite runtime-dependency experiment and backup acceptance analysis: preserve the source representation and interpretation rules, not only the final database.
A preserved value can lose its measurement state
Identifiers are not the only concern. A bounded follow-up reproduced on Python SQLite 3.45.1 and 3.53.1 used four inputs: 10.0, floating-point NaN, 30.0 and explicit absence. The finite values represent milliseconds in this designed example, not observations from a drive fleet. Reopened rows contained two REAL values and two NULLs.
A direct C API control on system SQLite 3.45.1 also bound NaN as NULL, without a table or Python's SQLite adapter. In the pinned upstream source, sqlite3_bind_double calls a value setter that leaves NaN as NULL. The conversion precedes column validation, so even STRICT ANY cannot recover its origin. A text-bound NaN is a different input and remained TEXT. [9] [10]
CHECK(x >= 0) and CHECK(x = x) accepted this NULL; CHECK does not reject a NULL result. Adding NOT NULL rejected both NaN and absence in the tested schema. Positive infinity, however, passed NOT NULL plus the nonnegative check. Presence, sign and finiteness are separate requirements. A finite domain bound rejected infinity in our control; that illustrative bound is not a universal latency limit. [11]
| Query | Result | Meaning |
|---|---|---|
COUNT(*) | 4 | Stored records |
COUNT(x) | 2 | Non-NULL measurements |
SUM(x) | 40 | Sum of retained values, ms |
AVG(x) | 20 | Mean of retained values, ms |
AVG(COALESCE(x,0)) | 10 | Zero-filled mean, ms |
The mean of 20 ms is correct for the two retained measurements. The 10 ms result assigns zero to the other records; it does not recover four valid readings. Once both reasons are encoded as NULL, the aggregate cannot distinguish invalid from absent. SQLite's aggregates document their non-NULL populations. [12]
A separate signed-infinity control grouped positive and negative infinity together, with 10 in another group. Direct SUM returned NULL, but explicitly summing the group subtotals returned 10: the outer SUM skipped the indeterminate NULL subtotal. A missing-only group also had a NULL subtotal, but COUNT(x) was zero instead of two. Keep contributing counts and an explicit invalid, empty or valid status with partial results. This is not a valid latency workload, an optimizer-rewrite claim or a proof of partition-invariant finite arithmetic. [12]
The completed backup retained the converted rows, aggregates and successful integrity checks. A positive control classified inputs before binding and retained raw binary64 bits where available; its backup preserved distinct NaN and missing states. That preserves supplied provenance, not independent proof that the original sensor was correct.
Counts diagnose the infinity-subtotal fixture; they do not replace pre-bind measurement status. A NaN already converted to NULL is also excluded from COUNT(x), as the four-input example shows. Preserve the input's status before conversion and carry it through partial summaries, rather than trying to reconstruct it from a later count or finite result. [10] [12]
This connects to the SMART missingness audit, whose selected cohorts contained no invalid nonblank readings. These designed SQLite fixtures do not change that field result or show that Backblaze used this ingestion path.
Exact rows, different aggregate outcomes
Import is only one boundary. A second experiment stored 9223372036854775807, 1 and -1 as exact INTEGER values in a STRICT table. Their mathematical sum fits the signed 64-bit range. Yet the same unordered SUM query failed or succeeded when the available index changed. Both recorded SQLite builds, 3.45.1 and 3.53.1, showed this sequence.
| SQLite | Index state | Unordered SUM | SUM ordered by id | SUM ordered by x,id | TOTAL minus exact sum |
|---|---|---|---|---|---|
| 3.45.1 | No secondary index | Integer overflow | Integer overflow | M | 1 integer unit |
| 3.45.1 | Covering (g,x ASC) | M | Integer overflow | M | 1 integer unit |
| 3.45.1 | Covering (g,x DESC) | Integer overflow | Integer overflow | M | 1 integer unit |
| 3.45.1 | Index removed | Integer overflow | Integer overflow | M | 1 integer unit |
| 3.53.1 | No secondary index | Integer overflow | Integer overflow | M | 1 integer unit |
| 3.53.1 | Covering (g,x ASC) | M | Integer overflow | M | 1 integer unit |
| 3.53.1 | Covering (g,x DESC) | Integer overflow | Integer overflow | M | 1 integer unit |
| 3.53.1 | Index removed | Integer overflow | Integer overflow | M | 1 integer unit |
Adding 1 before subtracting 1 crosses the integer limit. Every stored row remained exact and every integrity_check returned ok. Read-only queries left the database bytes unchanged within each index state; creating or removing an index deliberately changed the file between states. This is an arithmetic boundary, not database corruption. Index selection is an observation, not a planner promise. [18]
An outer ORDER BY sorts output rows, not aggregate inputs. Aggregate-local ordering specifies input order; include a unique tie-breaker when ties matter. A specified unsafe sequence still overflows. TOTAL(x) and SUM(CAST(x AS REAL)) avoided the error here but returned exactly 9223372036854775808, one above the integer answer. Casting SUM's result is too late to prevent an error inside SUM. [12] [3]
The scalar expression (9223372036854775807+1)-1 instead returned REAL 2^63. Scalar overflow and integer SUM have different contracts. The pinned aggregate implementation already uses compensated floating-point accumulation; the rounded result is not evidence of a naive accumulator. [19] [20]
When every order is safe
For the finite list of non-NULL input expressions actually having INTEGER storage class, compute P, the sum of positive values, and N, the sum of negative values, using wider exact arithmetic. Every ordinary sequential accumulation order stays within signed 64-bit bounds exactly when P <= 9223372036854775807 and N >= -9223372036854775808. Each partial sum lies between N and P; putting all positive or all negative terms first proves why each bound is necessary.
Nonnegative inputs whose exact total fits are therefore safe in every order. Signed corrections can have a small final sum but an overflowing subtotal. Ascending order is not a universal fix: the sequence -9223372036854775808, -1, 1 underflows before reaching its representable final sum. This certificate excludes REAL or TEXT inputs and sliding-window inverse operations. Empty or all-NULL SUM returns NULL, not zero. [12]
For exact storage accounting, validate the reopened inputs and derived totals against an arbitrary-precision oracle. Compute the bounds outside the bounded SUM being checked. Using TOTAL is an explicit approximation policy, not an exact-counter repair. These are designed software controls, not hardware failures, typical telemetry magnitudes or a failure-rate sample.
The type-affinity record connects import and aggregation. Download the complete replay package, generated eight-row summary, source ledger and file hashes.
python3 -B validate.py --check
python3 -B -m unittest -v test_evidence test_native_bounds
python3 -B -O -m unittest -v test_evidence test_native_bounds
python3 -B probe.py --output observation-new.jsonExtract into an empty directory. Python 3.11+ with SQLite 3.44+ is required; no external package or production database is used. Strict replay tests require a retained SQLite source ID. A different build needs investigation, not a silent replacement of historical results. Keep the frozen captures unchanged. Replay requirements and limits.
Set the CSV contract before importing values
Comma-separated values (CSV) supplies field boundaries, not a database schema. RFC 4180 describes a common format with optional headers and quoted line breaks. Splitting on every comma or newline can change the records before numeric validation begins. [CSV format]
| Boundary | What to establish |
|---|---|
| Bytes to fields | Encoding, delimiter, quoting and embedded newlines. |
| Fields to columns | Header policy, column count, names and order. |
| Text to values | Identifier spelling, exact numeric range and explicit missing-value rules. |
| Values to storage | Binding types, target schema and reopened value comparison. |
The default Python CSV reader yields strings; QUOTE_NONNUMERIC converts unquoted fields to floats. Quotation is a syntax choice, not a portable type declaration. Open text files with newline='' as documented, and validate row width and identifiers separately from parsing. Even strict=True does not enforce equal column counts. [Python CSV]
The SQLite CLI has a separate header rule: when .import creates the target table, it uses the first input row as column names. If the table already exists, that row is data unless explicitly skipped. Pre-create the intended table and schema, then use .import --csv --skip 1 when the input has a header; the explicit format flag avoids inheriting unrelated output-mode delimiters. This CLI behavior is separate from the parameter-binding experiment above. [SQLite import]
Missingness has its own conversion boundary. The existing CSV recovery experiment shows how a rewrite can discard the distinction between NULL and empty text. Keep its reader-version qualifications: a later parser cannot reconstruct the lost distinction from those CSV bytes alone.
Preserve first, then validate the interpretation
For archival ingestion, retain raw source text or bytes alongside deliberately parsed values. Bind identifiers as strings; when using STRICT ANY, enforce the intended input type in the importer. A STRICT TEXT column also preserved every text-bound fixture here, but converting an already rounded float to text did not recover the source.
For exact integral quantities, validate syntax, integrality and signed 64-bit range before integer binding. Keep larger values in an explicitly documented representation. Validate reopened results against an exact external oracle and expected identifiers. Do not use a SQL equality comparison that repeats the same conversion as the import.
Reproduce the observations
Download the stdlib-only harness, seven regression tests and complete JSON evidence. Keep the two Python files in one directory. The harness creates and removes only its own temporary databases; the output path is explicit.
python3 observe.py --output results.json
python3 test_observe.pyThe tests encode this recorded behavior; a different runtime may require investigation rather than silently updating the expected values. The JSON stores measured numbers as strings with explicit types, avoiding a second large-integer conversion in a consumer.
The original identifier matrix uses Python 3.12.3 and SQLite 3.45.1; the separate telemetry supplement retains two Python SQLite runtimes, 3.45.1 and 3.53.1, with system-C controls on 3.45.1 only. Designed fixtures, not a failure-rate estimate or newly discovered vulnerability. No custom adapters, crash, WAL or concurrent writer. Pinned upstream source explains mechanisms but is not asserted byte-identical to installed distribution binaries. The sorting supplement uses one recorded x86-64 runtime with a 64-bit long-double significand. No non-C locale, physical smartctl capture, external-merge performance or hardware experiment; the Goldberg spacing explanation is a derivation, not a new measurement. Aggregation captures differ in version and environment, so they do not isolate a version effect. The all-order subtotal certificate concerns INTEGER-only sequential aggregation, not REAL/TEXT inputs or sliding-window inverse operations; nonnegative in-range totals are safe. The source ID is recorded in the JSON. No experimental SQLite build or third-party package was installed.
Replay the telemetry supplement
The complete replay package includes the original probe, both observations, 20 test methods, source ledger and synthesis. Inspect the machine-readable findings, source records and file hashes. No third-party documentation or source is bundled.
Extract the package into an empty directory. It requires Python 3.11+, Python SQLite with STRICT support and a system SQLite library discoverable by ctypes. No package installation, production database or device access is needed. Missing C-library support is an error, not a passed control.
python3 -B probe.py --output observation-new.json
python3 -B -m unittest -v test_probe test_evidence
python3 -B -O -m unittest -v test_probe test_evidenceKeep the frozen captures unchanged. The full experiment used Python SQLite 3.45.1 and 3.53.1, while both separately linked C controls used 3.45.1. Runtime source IDs and compile options scope the observations. This is no compatibility survey, field incidence estimate, power-loss test or new vulnerability claim. The package notes describe limits and artifact-specific rights.
Replay the preprocessing supplement
The complete sorting experiment contains both frozen captures, Python harness, C probe, tests and source receipts. Inspect the generated table data, six primary-source records, file hashes and method and limits.
python3 -B run.py --output capture-new.json
python3 -B run.py --verify capture-new.json
python3 -B -m unittest -v test_run
python3 -B -O -m unittest -v test_runRequirements are Python 3.11+ with sqlite3, GNU sort/uniq and a C11 compiler. Only a private temporary compiler directory and the named output are written. The two original captures repeat one host, not independent platforms; their tests retain its 64-bit-significand profile. Different native precision requires investigation, not changing the frozen evidence. There was no disk durability, hardware telemetry, performance or fleet-risk experiment.
Primary sources
- SQLite: STRICT Tables, sections 2 and 3
- SQLite: Datatypes, numeric affinity and storage classes
- SQLite: Floating Point Numbers
- SQLite version-3.45.1: applyNumericAffinity and OP_TypeCheck
- SQLite version-3.45.1: sqlite3VdbeIntegerAffinity
- Python 3.12 sqlite3: parameter types, backup and error attributes
- SQLite: integrity_check scope
- SQLite: extended result codes 3091 and 2067
- SQLite 3.45.1 pinned source: sqlite3_bind_double
- SQLite 3.45.1 pinned source: sqlite3VdbeMemSetDouble
- SQLite: CHECK and NOT NULL constraint semantics
- SQLite: aggregate populations and indeterminate sums
- GNU Coreutils 9.4: numeric grammar, uniqueness and stable sorting
- GNU Coreutils 9.4 sort.c: general_numcompare and last-resort comparison
- smartctl pinned manual: verbose JSON integer representations
- RFC 8259 section 6: JSON numeric precision and interoperability
- David Goldberg (1991), What Every Computer Scientist Should Know About Floating-Point Arithmetic: permitted edited reprint, Floating-point Formats and Relative Error and Ulps; DOI 10.1145/103162.103163
- SQLite: EXPLAIN QUERY PLAN and covering indexes
- SQLite: scalar arithmetic and CAST expressions
- SQLite 3.45.1 pinned func.c: sumStep, sumFinalize and totalFinalize
- RFC 4180: common CSV format and text/csv registration, sections 2 and 3
- Python 3.12: CSV reader, writer and dialect contracts
- SQLite CLI: importing files as CSV or other formats, section 7.5