fix(sqlite): normalize column names in ALTER TABLE ADD/DROP COLUMN#4308
Open
stakeswky wants to merge 1 commit intosqlc-dev:mainfrom
Open
fix(sqlite): normalize column names in ALTER TABLE ADD/DROP COLUMN#4308stakeswky wants to merge 1 commit intosqlc-dev:mainfrom
stakeswky wants to merge 1 commit intosqlc-dev:mainfrom
Conversation
Fixes sqlc-dev#4307 When ALTER TABLE ADD COLUMN or DROP COLUMN statements use mixed-case column names (e.g., barBaz), the column name was stored in the catalog with its original case. However, SELECT queries normalize all unquoted identifiers to lowercase via the identifier() function, causing a mismatch and 'column does not exist' errors. This fix ensures ALTER TABLE ADD/DROP COLUMN also normalize column names using identifier(), matching the behavior of CREATE TABLE and SELECT queries. This aligns with SQLite's case-insensitive identifier handling. Changes: - internal/engine/sqlite/convert.go: Apply identifier() to column names in ALTER TABLE ADD COLUMN and DROP COLUMN handlers - internal/engine/sqlite/catalog_test.go: Add regression test for mixed-case column names in ALTER TABLE ADD COLUMN
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.
Fixes #4307
Problem
When or statements use mixed-case column names (e.g.,
barBaz), the column name was stored in the catalog with its original case. However, queries normalize all unquoted identifiers to lowercase via theidentifier()function, causing a mismatch and "column does not exist" errors.Solution
This fix ensures also normalize column names using
identifier(), matching the behavior of and queries. This aligns with SQLite's case-insensitive identifier handling.Changes
internal/engine/sqlite/convert.go: Applyidentifier()to column names in ALTER TABLE ADD COLUMN and DROP COLUMN handlers (lines 70 and 91)internal/engine/sqlite/catalog_test.go: Add regression test for mixed-case column names in ALTER TABLE ADD COLUMNTesting
All existing tests pass, including the new regression test case that reproduces the issue from #4307.