Skip to content

Commit 93262c8

Browse files
committed
Identitfy NULLS FIRST/LAST as keywords (fixes andialbrecht#487).
1 parent 913b56e commit 93262c8

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Bug Fixes
99

1010
* Fix splitting of SQL with multiple statements inside
1111
parentheses (issue485, pr486 by win39).
12+
* Correctly identify NULLS FIRST / NULLS LAST as keywords (issue487).
1213

1314

1415
Release 0.3.0 (Mar 11, 2019)

sqlparse/keywords.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def is_keyword(value):
7878
r'|(CROSS\s+|NATURAL\s+)?)?JOIN\b', tokens.Keyword),
7979
(r'END(\s+IF|\s+LOOP|\s+WHILE)?\b', tokens.Keyword),
8080
(r'NOT\s+NULL\b', tokens.Keyword),
81+
(r'NULLS\s+(FIRST|LAST)\b', tokens.Keyword),
8182
(r'UNION\s+ALL\b', tokens.Keyword),
8283
(r'CREATE(\s+OR\s+REPLACE)?\b', tokens.Keyword.DDL),
8384
(r'DOUBLE\s+PRECISION\b', tokens.Name.Builtin),

tests/test_tokenize.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,13 @@ def test_parse_endifloop(s):
171171
assert p.tokens[0].ttype is T.Keyword
172172

173173

174+
@pytest.mark.parametrize('s', ['NULLS FIRST', 'NULLS LAST'])
175+
def test_parse_nulls(s): # issue487
176+
p = sqlparse.parse(s)[0]
177+
assert len(p.tokens) == 1
178+
assert p.tokens[0].ttype is T.Keyword
179+
180+
174181
@pytest.mark.parametrize('s', [
175182
'foo',
176183
'Foo',

0 commit comments

Comments
 (0)