Recognize MATERIALIZED as a keyword (issue752)#854
Open
gaoflow wants to merge 1 commit into
Open
Conversation
MATERIALIZED was missing from the KEYWORDS table, so in statements like CREATE MATERIALIZED VIEW the token was lexed as a Name rather than a Keyword. This left it untouched by keyword_case formatting, producing inconsistent output (e.g. 'CREATE materialized VIEW ...' under keyword_case='upper') while every other DDL keyword was normalized. Add MATERIALIZED to KEYWORDS, alongside the existing VIEW keyword, so it parses and formats consistently.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes parsing/formatting of CREATE MATERIALIZED VIEW statements by treating MATERIALIZED as a SQL keyword, and adds a regression test and changelog entry for issue752.
Changes:
- Add
MATERIALIZEDto the keyword list so it tokenizes asKeyword. - Add a regression test ensuring parsing and keyword uppercasing behave correctly for materialized views.
- Document the bug fix in
CHANGELOGand add contributor toAUTHORS.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_regressions.py | Adds regression test for CREATE MATERIALIZED VIEW parsing/formatting. |
| sqlparse/keywords.py | Registers MATERIALIZED as a keyword token. |
| CHANGELOG | Documents the fix for consistent parsing/formatting (issue752). |
| AUTHORS | Adds contributor attribution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+457
to
+459
| def test_materialized_view_issue752(): | ||
| p = sqlparse.parse('CREATE MATERIALIZED VIEW v AS SELECT 1')[0] | ||
| assert p.tokens[2].ttype == T.Keyword |
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 #752.
MATERIALIZEDis absent from theKEYWORDStable, so in statements likeCREATE MATERIALIZED VIEWthe token is lexed as aNameinstead of aKeyword. That leaves it untouched bykeyword_caseformatting, producing inconsistent output while every other DDL keyword is normalized:CREATE,VIEW,ASandSELECTare all uppercased; onlymaterializedis left alone.Fix
Add
'MATERIALIZED': tokens.KeywordtoKEYWORDS, next to the existingVIEWkeyword.MATERIALIZEDis a standard SQL keyword used forCREATE/REFRESH/DROP MATERIALIZED VIEWacross PostgreSQL, Oracle, BigQuery and Snowflake, so classifying it as a keyword matches both the spec and how sqlparse already treatsVIEW.After the change the token is a
Keywordandkeyword_case='upper'yieldsCREATE MATERIALIZED VIEW x.y.z AS SELECT 1.Tests
Added
test_materialized_view_issue752intests/test_regressions.py, asserting the token is aKeywordand thatkeyword_case='upper'normalizes it. The test is RED on the unpatched table and GREEN with the fix; the full suite stays green (488 passed, 2 xfailed, 1 xpassed). CHANGELOG and AUTHORS updated.Disclosure: I prepared this fix with AI assistance under my direction; I reviewed and verified the change and the test myself.