SQLite generated column
A SQLite generated column derives its value from an expression over columns in the same row, with STORED values materialized on writes and VIRTUAL values evaluated on reads.
Generated expressions require deterministic scalar functions. Generated columns are absent from table_info but included in table_xinfo, whose hidden flag is 2 for virtual and 3 for stored. [1] [2]
In seven controlled SQLite 3.45.1 observations, changing score(x) from x to x+100 left old STORED values in reopened, reindexed and backup copies while VIRTUAL values changed; integrity_check returned ok throughout. Python SQL-dump replay under the new callback recomputed stored values. Preserve or deliberately migrate the function implementation as well as the database. [3]
A further three-case UNIQUE replay experiment changed the callback so two inputs generated the same key. Replay stopped at the second INSERT but left the first in an active transaction; explicit rollback discarded the import, whereas deliberately committing preserved an incomplete one-row table that passed integrity_check. Treat replay success and application completeness as separate acceptance checks. [4]
A separate two-build experiment copied historical stale STORED values through completed backup, VACUUM INTO and compatible-schema INSERT SELECT star; integrity_check returned ok. Explicit ordinary-column projection recomputed the fixture. Indexed VIRTUAL inconsistencies survived the same raw-transfer paths but were detected by full checking. SQL syntax alone does not establish recomputation. [5]
On recorded 3.45.1 and 3.54.1 readers, inherited stale STORED values passed full checks through read-only and read/write connections. Blocking new BLOB writes does not revalidate old files. Recomputing a value also does not restore its historical input. [6]
Relations
Limitations
- Changing a function implementation can violate the schema's determinism assumption; the controls are not a newly discovered SQLite defect.
Citations
- SQLite: Generated Columns
- SQLite PRAGMA table_xinfo: generated-column flags
- Hesela: SQLite stored generated-column controls
- Hesela: generated-column replay failures and transaction finalization
- Hesela: native recovery-copy controls, exact build scope and source synthesis
- Hesela: supplemental legacy generated-value controls, exact builds and RO/RW checks
Sources & caveats
- Seven designed cases on SQLite 3.45.1 and Python 3.12.3; closed DELETE-journal fixtures, no failure-rate estimate. Full rows, scripts and runtime identity are linked from the analysis.
- Three additional UNIQUE-constrained SQL replay controls on the same runtime; explicit rollback and deliberately unsafe commit after an error. Not a crash test or general import-tool guarantee.
- 160 synthetic recovery configurations on recorded SQLite 3.45.1 and 3.54.1 builds; old-build seeds, closed files, two source journal settings. Not an incidence estimate or new vulnerability. Exact captures and reproduction package linked from the analysis.
- Supplement: 24 outcomes from six actions, two reader builds and two closed journal configurations, with explicit RO/RW checks. Corroborates the earlier mechanism on the same host; no independent replication, incidence or crash test.