Skip to content

Commit

Permalink
Never interpret IN keyword as function name (fixes #183).
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Apr 12, 2015
1 parent ab827ea commit f775030
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Bug Fixes
* Fix parsing of multi-line comments (issue172, by JacekPliszka).
* Fix parsing of escaped backslashes (issue174, by caseyching).
* Fix parsing of identifiers starting with underscore (issue175).
* Fix misinterpretation of IN keyword (issue183).

Enhancements
* Improve formatting of HAVING statements.
Expand Down
3 changes: 3 additions & 0 deletions sqlparse/lexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ class Lexer(object):
# see https://github.com/andialbrecht/sqlparse/pull/64
(r'VALUES', tokens.Keyword),
(r'@[^\W\d_]\w+', tokens.Name),
# IN is special, it may be followed by a parenthesis, but
# is never a functino, see issue183
(r'in\b(?=[ (])?', tokens.Keyword),
(r'[^\W\d_]\w*(?=[.(])', tokens.Name), # see issue39
(r'[-]?0x[0-9a-fA-F]+', tokens.Number.Hexadecimal),
(r'[-]?[0-9]*(\.[0-9]+)?[eE][-]?[0-9]+', tokens.Number.Float),
Expand Down
8 changes: 7 additions & 1 deletion tests/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,12 @@ def test_function(self):
self.assert_(isinstance(p.tokens[0], sql.Function))
self.assertEqual(len(list(p.tokens[0].get_parameters())), 2)

def test_function_not_in(self): # issue183
p = sqlparse.parse('in(1, 2)')[0]
self.assertEqual(len(p.tokens), 2)
self.assertEqual(p.tokens[0].ttype, T.Keyword)
self.assert_(isinstance(p.tokens[1], sql.Parenthesis))

def test_varchar(self):
p = sqlparse.parse('"text" Varchar(50) NOT NULL')[0]
self.assert_(isinstance(p.tokens[2], sql.Function))
Expand Down Expand Up @@ -385,4 +391,4 @@ def test_aliased_function_without_as():
def test_aliased_literal_without_as():
p = sqlparse.parse('1 foo')[0].tokens
assert len(p) == 1
assert p[0].get_alias() == 'foo'
assert p[0].get_alias() == 'foo'

0 comments on commit f775030

Please sign in to comment.