summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2015-04-12 07:37:01 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2015-04-12 07:37:01 +0200
commitf775030692222a5a0b296284328276b65259cc02 (patch)
treea04aee084828f9389b870fc68614f1fa86c3b21c
parentab827eaf935aba776715c4693ec9f320008a6708 (diff)
downloadsqlparse-f775030692222a5a0b296284328276b65259cc02.tar.gz
Never interpret IN keyword as function name (fixes #183).
-rw-r--r--CHANGES1
-rw-r--r--sqlparse/lexer.py3
-rw-r--r--tests/test_grouping.py8
3 files changed, 11 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 4229de3..51a2551 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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.
diff --git a/sqlparse/lexer.py b/sqlparse/lexer.py
index a1a4703..9533e8a 100644
--- a/sqlparse/lexer.py
+++ b/sqlparse/lexer.py
@@ -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),
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index c598258..b6edafe 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -207,6 +207,12 @@ class TestGrouping(TestCaseBase):
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))
@@ -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' \ No newline at end of file
+ assert p[0].get_alias() == 'foo'