Fix transform() corrupting ANY columns on STRICT tables to REAL - #820
Open
ikatyal2110 wants to merge 1 commit into
Open
Fix transform() corrupting ANY columns on STRICT tables to REAL#820ikatyal2110 wants to merge 1 commit into
ikatyal2110 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SQLite's
ANYcolumn type (only valid in STRICT tables) was not handled bycolumn_affinity(). The function fell through all its checks and returnedfloat, which then mapped toREALinCOLUMN_TYPE_MAPPING. As a result, callingtransform()on a STRICT table withANYcolumns either crashed withIntegrityError: cannot store TEXT value in REAL columnwhen rows held non-numeric data, or silently changed the column type fromANYtoREAL.The fix adds
ANYas an explicit case incolumn_affinity()— it returns the string"ANY"rather thanfloat— and registers"ANY"and"any"inCOLUMN_TYPE_MAPPINGso thatcreate_table_sql()emits the correct column type. Both the strict-to-strict and strict-to-non-strict transform paths now preserveANYcolumns unchanged.A regression test is included that creates a STRICT table with an
ANYcolumn, inserts rows with integer, text, and float values, and verifies thattransform()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/