From 3e3c7b89eec2f088faa8143ab8d95beb79af92bd Mon Sep 17 00:00:00 2001 From: Vincent Gao Date: Tue, 16 Jun 2026 08:49:42 +0200 Subject: [PATCH] Recognize MATERIALIZED as a keyword (issue752) 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. --- AUTHORS | 1 + CHANGELOG | 2 ++ sqlparse/keywords.py | 1 + tests/test_regressions.py | 8 ++++++++ 4 files changed, 12 insertions(+) diff --git a/AUTHORS b/AUTHORS index 872c7007..0a8e884f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -82,6 +82,7 @@ Alphabetical list of contributors: * Victor Hahn * Victor Uriarte * Ville Skyttä +* Vincent Gao * vthriller * wayne.wuw * Will Jones diff --git a/CHANGELOG b/CHANGELOG index edfedb4f..ec187aaa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,8 @@ Bug Fixes * Fix statement splitting (issue845). * Fix a late-binding closure bug in `TokenList.token_not_matching`. +* Recognize ``MATERIALIZED`` as a keyword so it is parsed and formatted + consistently in ``CREATE MATERIALIZED VIEW`` statements (issue752). Release 0.5.5 (Dec 19, 2025) diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 4bafcda1..631aa2e0 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -359,6 +359,7 @@ # 'M': tokens.Keyword, 'MAP': tokens.Keyword, 'MATCH': tokens.Keyword, + 'MATERIALIZED': tokens.Keyword, 'MAXEXTENTS': tokens.Keyword, 'MAXVALUE': tokens.Keyword, 'MESSAGE_LENGTH': tokens.Keyword, diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 15ac9ee9..2265f363 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -454,6 +454,14 @@ def test_primary_key_issue740(): assert p.tokens[0].ttype == T.Keyword +def test_materialized_view_issue752(): + p = sqlparse.parse('CREATE MATERIALIZED VIEW v AS SELECT 1')[0] + assert p.tokens[2].ttype == T.Keyword + formatted = sqlparse.format('create materialized view v as select 1', + keyword_case='upper') + assert formatted == 'CREATE MATERIALIZED VIEW v AS SELECT 1' + + @pytest.fixture def limit_recursion(): curr_limit = sys.getrecursionlimit()