From 46971e5a804b29e7dbd437155a8ceffab8ef1cd5 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sat, 16 Mar 2024 17:03:23 +0100 Subject: [PATCH] Fix parsing of PRIMARY KEY (fixes #740). --- CHANGELOG | 3 ++- sqlparse/keywords.py | 1 + tests/test_regressions.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 6aa1e278..745328e6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -23,7 +23,8 @@ Bug Fixes * Fix parsing of nested order clauses (issue745, pr746 by john-bodley). * Thread-safe initialization of Lexer class (issue730). * Classify TRUNCATE as DDL and GRANT/REVOKE as DCL keywords (based on pr719 - by josuc1, thanks for bringing this up!) + by josuc1, thanks for bringing this up!). +* Fix parsing of PRIMARY KEY (issue740). Release 0.4.4 (Apr 18, 2023) diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py index 029d8bae..3b963557 100644 --- a/sqlparse/keywords.py +++ b/sqlparse/keywords.py @@ -77,6 +77,7 @@ (r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin), (r'GROUP\s+BY\b', tokens.Keyword), (r'ORDER\s+BY\b', tokens.Keyword), + (r'PRIMARY\s+KEY\b', tokens.Keyword), (r'HANDLER\s+FOR\b', tokens.Keyword), (r'GO(\s\d+)\b', tokens.Keyword), (r'(LATERAL\s+VIEW\s+)' diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 961adc17..29cb502c 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -444,3 +444,9 @@ def test_copy_issue672(): p = sqlparse.parse('select * from foo')[0] copied = copy.deepcopy(p) assert str(p) == str(copied) + + +def test_primary_key_issue740(): + p = sqlparse.parse('PRIMARY KEY')[0] + assert len(p.tokens) == 1 + assert p.tokens[0].ttype == T.Keyword \ No newline at end of file