Skip to content

Fix transform() corrupting ANY columns on STRICT tables to REAL - #820

Open
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-any-column-transform
Open

Fix transform() corrupting ANY columns on STRICT tables to REAL#820
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-any-column-transform

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

SQLite's ANY column type (only valid in STRICT tables) was not handled by column_affinity(). The function fell through all its checks and returned float, which then mapped to REAL in COLUMN_TYPE_MAPPING. As a result, calling transform() on a STRICT table with ANY columns either crashed with IntegrityError: cannot store TEXT value in REAL column when rows held non-numeric data, or silently changed the column type from ANY to REAL.

The fix adds ANY as an explicit case in column_affinity() — it returns the string "ANY" rather than float — and registers "ANY" and "any" in COLUMN_TYPE_MAPPING so that create_table_sql() emits the correct column type. Both the strict-to-strict and strict-to-non-strict transform paths now preserve ANY columns unchanged.

A regression test is included that creates a STRICT table with an ANY column, inserts rows with integer, text, and float values, and verifies that transform() completes without error and preserves the column type and all row data.

Fixes #790


Generated by Claude Code


📚 Documentation preview 📚: https://sqlite-utils--820.org.readthedocs.build/en/820/

column_affinity() fell through all type checks for the SQLite-specific
ANY column type and returned float, which then mapped to REAL in
COLUMN_TYPE_MAPPING. This caused transform() on a STRICT table with
ANY columns to either crash with IntegrityError (when existing rows
held non-numeric values) or silently change the column type from ANY
to REAL.

Add ANY as an explicit case in column_affinity() so it passes through
as the string "ANY", and register "ANY"/"any" in COLUMN_TYPE_MAPPING
so create_table_sql() emits the correct column type.

Fixes simonw#790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support ANY column types for strict tables

1 participant