Skip to content

Commit 28c4d40

Browse files
hurcyandialbrecht
authored andcommitted
add regex pattern to identify IN as a Compasion token
1 parent d5d4bde commit 28c4d40

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

sqlparse/keywords.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def is_keyword(value):
4444
(r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder),
4545

4646
(r'\\\w+', tokens.Command),
47-
47+
(r'(NOT\s+)?(IN)\b', tokens.Operator.Comparison),
4848
# FIXME(andi): VALUES shouldn't be listed here
4949
# see https://github.com/andialbrecht/sqlparse/pull/64
5050
# AS and IN are special, it may be followed by a parenthesis, but

tests/test_grouping.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,20 @@ def test_grouping_function_not_in():
371371
# issue183
372372
p = sqlparse.parse('in(1, 2)')[0]
373373
assert len(p.tokens) == 2
374-
assert p.tokens[0].ttype == T.Keyword
374+
assert p.tokens[0].ttype == T.Comparison
375375
assert isinstance(p.tokens[1], sql.Parenthesis)
376376

377377

378+
def test_in_comparison():
379+
# issue566
380+
p = sqlparse.parse('a in (1, 2)')[0]
381+
assert len(p.tokens) == 1
382+
assert isinstance(p.tokens[0], sql.Comparison)
383+
assert len(p.tokens[0].tokens) == 5
384+
assert p.tokens[0].left.value == 'a'
385+
assert p.tokens[0].right.value == '(1, 2)'
386+
387+
378388
def test_grouping_varchar():
379389
p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
380390
assert isinstance(p.tokens[2], sql.Function)

0 commit comments

Comments
 (0)