Skip to content

Commit

Permalink
add regex pattern to identify IN as a Compasion token
Browse files Browse the repository at this point in the history
  • Loading branch information
hurcy authored and andialbrecht committed Sep 13, 2020
1 parent d5d4bde commit 28c4d40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sqlparse/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def is_keyword(value):
(r'(?<!\w)[$:?]\w+', tokens.Name.Placeholder),

(r'\\\w+', tokens.Command),

(r'(NOT\s+)?(IN)\b', tokens.Operator.Comparison),
# FIXME(andi): VALUES shouldn't be listed here
# see https://github.com/andialbrecht/sqlparse/pull/64
# AS and IN are special, it may be followed by a parenthesis, but
Expand Down
12 changes: 11 additions & 1 deletion tests/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,20 @@ def test_grouping_function_not_in():
# issue183
p = sqlparse.parse('in(1, 2)')[0]
assert len(p.tokens) == 2
assert p.tokens[0].ttype == T.Keyword
assert p.tokens[0].ttype == T.Comparison
assert isinstance(p.tokens[1], sql.Parenthesis)


def test_in_comparison():
# issue566
p = sqlparse.parse('a in (1, 2)')[0]
assert len(p.tokens) == 1
assert isinstance(p.tokens[0], sql.Comparison)
assert len(p.tokens[0].tokens) == 5
assert p.tokens[0].left.value == 'a'
assert p.tokens[0].right.value == '(1, 2)'


def test_grouping_varchar():
p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
assert isinstance(p.tokens[2], sql.Function)
Expand Down

0 comments on commit 28c4d40

Please sign in to comment.