fix(duckdb): Always quote column names in INSERT statements to handle reserved words #11612
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.
The DuckDB backend was failing to create tables when column names were SQL reserved words like "group". This occurred because INSERT statements generated during table creation were not properly quoting column identifiers, causing parser errors.
Problem:
Root Cause:
The
create_tablemethod in the DuckDB backend generated INSERT statements using the globalquotedsetting from the compiler. When column names were reserved words, unquoted identifiers likeINSERT INTO table (group) ...would cause SQL parser errors sinceGROUPis a reserved keyword.Solution:
Modified the column identifier generation in INSERT statements to always use
quoted=True, ensuring reserved words are properly escaped:INSERT INTO table (group, "order", normal_col)INSERT INTO table ("group", "order", "normal_col")This follows the existing pattern used for struct fields where
sg.to_identifier(name, quoted=True)handles reserved words defensively.Testing:
Fixes #11591.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.