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