-
-
Notifications
You must be signed in to change notification settings - Fork 123
Use double quotes not braces for tables and columns #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #678 +/- ##
==========================================
- Coverage 95.28% 95.27% -0.01%
==========================================
Files 8 8
Lines 3009 3008 -1
==========================================
- Hits 2867 2866 -1
Misses 142 142 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| def test_create_table_with_invalid_column_characters(fresh_db): | ||
| with pytest.raises(AssertionError): | ||
| fresh_db.create_table("players", {"name[foo]": str}) | ||
| def test_create_table_with_special_column_characters(fresh_db): | ||
| # With double-quote escaping, columns with special characters are now valid | ||
| table = fresh_db.create_table("players", {"name[foo]": str}) | ||
| assert ["players"] == fresh_db.table_names() | ||
| assert [{"name": "name[foo]", "type": "TEXT"}] == [ | ||
| {"name": col.name, "type": col.type} for col in table.columns | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice bonus from switching from [] to "".
| "FTS5", | ||
| ( | ||
| "with original as (\n" | ||
| 'with "original" as (\n' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know this worked but it does:
with "everything" as (select * from binary_data)
select * from everything| AND sql LIKE '% INSERT INTO [{}]%' | ||
| AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat that this detects the old AND new form of table quoting.
|
Updated the docs to use |
|
Testing this manually. With previous version: echo '{"id": 1, "name": "Cleo", "age": 10}' | \
uvx 'sqlite-utils==3.38' insert /tmp/dogs.db dogs -
uvx sqlite-utils schema /tmp/dogs.dbOutputs: CREATE TABLE [dogs] (
[id] INTEGER,
[name] TEXT,
[age] INTEGER
);But with the current branch: echo '{"id": 1, "name": "Cleo", "age": 10}' | \
uv run --with https://github.com/simonw/sqlite-utils/archive/b6e0885aa67e71e57ea55f4a96a4d69a725ed771.zip \
sqlite-utils insert /tmp/dogs.db dogs2 -
uvx sqlite-utils schema /tmp/dogs.db dogs2Output: CREATE TABLE "dogs2" (
"id" INTEGER,
"name" TEXT,
"age" INTEGER
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request updates sqlite-utils to use double quotes (") instead of square brackets ([]) for escaping table and column names in SQL queries. This change improves consistency with SQLite's standard identifier quoting syntax and enables support for special characters (like [ and ]) in table and column names.
Key changes:
- Introduced a new
quote_identifier()function that uses double quotes for SQL identifiers - Removed validation that prevented square brackets in column names
- Updated all SQL generation throughout the codebase to use the new quoting mechanism
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| sqlite_utils/db.py | Core implementation: added quote_identifier() function, removed bracket validation, updated all SQL generation to use double quotes |
| sqlite_utils/cli.py | Updated CLI commands to use the new quote_identifier() function |
| tests/*.py | Updated test expectations to match the new double-quote syntax |
| docs/.rst, docs/.ipynb | Updated documentation examples to reflect the new quoting syntax |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def test_update_alter_with_special_column_characters(fresh_db): | ||
| # With double-quote escaping, columns with special characters are now valid |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected spelling of 'characters' (no actual typo found, comment is correct)
| SELECT name FROM sqlite_master | ||
| WHERE type = 'trigger' | ||
| AND sql LIKE '% INSERT INTO [{}]%' | ||
| AND (sql LIKE '% INSERT INTO [{}]%' OR sql LIKE '% INSERT INTO "{}"%') |
Copilot
AI
Nov 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This SQL query includes both square bracket and double quote patterns for backward compatibility when detecting FTS triggers. This dual pattern check may be unnecessary if the codebase is fully migrated to double quotes. Consider whether the square bracket pattern can be removed or document why both patterns are needed.
|
Lots of examples of updated |
Refs:
📚 Documentation preview 📚: https://sqlite-utils--678.org.readthedocs.build/en/678/