summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredy Wijaya <fredy.wijaya@gmail.com>2018-12-01 10:57:25 -0600
committerAndi Albrecht <albrecht.andi@gmail.com>2018-12-03 14:15:11 +0100
commit4140d2ea1514b1d293cc4802880c2e414ffc615c (patch)
tree714f7e50fc65d66457d63c7f1b41d7459d847f02
parentafd05eeeebdd4360224dfeabcd60ed704fd705fa (diff)
downloadsqlparse-4140d2ea1514b1d293cc4802880c2e414ffc615c.tar.gz
Fix from( parsing issue (fixes #446)
-rw-r--r--sqlparse/keywords.py2
-rw-r--r--tests/test_parse.py18
2 files changed, 19 insertions, 1 deletions
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index 28545d8..985334d 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -47,7 +47,7 @@ SQL_REGEX = {
# see https://github.com/andialbrecht/sqlparse/pull/64
# IN is special, it may be followed by a parenthesis, but
# is never a function, see issue183
- (r'(CASE|IN|VALUES|USING)\b', tokens.Keyword),
+ (r'(CASE|IN|VALUES|USING|FROM)\b', tokens.Keyword),
(r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name),
diff --git a/tests/test_parse.py b/tests/test_parse.py
index d191f65..4fad526 100644
--- a/tests/test_parse.py
+++ b/tests/test_parse.py
@@ -435,6 +435,24 @@ def test_get_real_name():
assert 't' == stmts[0].get_alias()
+def test_from_subquery():
+ # issue 446
+ s = u'from(select 1)'
+ stmts = sqlparse.parse(s)
+ assert len(stmts) == 1
+ assert len(stmts[0].tokens) == 2
+ assert stmts[0].tokens[0].value == 'from'
+ assert stmts[0].tokens[0].ttype == T.Keyword
+
+ s = u'from (select 1)'
+ stmts = sqlparse.parse(s)
+ assert len(stmts) == 1
+ assert len(stmts[0].tokens) == 3
+ assert stmts[0].tokens[0].value == 'from'
+ assert stmts[0].tokens[0].ttype == T.Keyword
+ assert stmts[0].tokens[1].ttype == T.Whitespace
+
+
def test_parenthesis():
tokens = sqlparse.parse("(\n\n1\n\n)")[0].tokens[0].tokens
assert list(map(lambda t: t.ttype, tokens)) == [T.Punctuation,