summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Bodley <john.bodley@airbnb.com>2019-10-03 09:14:22 -0700
committerAndi Albrecht <albrecht.andi@gmail.com>2019-10-09 11:22:16 +0200
commit9902b885dc64c3503c024d3fd77acc0a7216109f (patch)
tree6bf2056849e658f9cced98914c671b97fbbe337f
parente8ae45d9f0e4238add9e24af2b8cfbc1665aab77 (diff)
downloadsqlparse-9902b885dc64c3503c024d3fd77acc0a7216109f.tar.gz
[fix] Addressing issue #507
-rw-r--r--sqlparse/keywords.py6
-rw-r--r--tests/test_grouping.py8
2 files changed, 11 insertions, 3 deletions
diff --git a/sqlparse/keywords.py b/sqlparse/keywords.py
index 53c83bb..ec3fe50 100644
--- a/sqlparse/keywords.py
+++ b/sqlparse/keywords.py
@@ -48,9 +48,9 @@ SQL_REGEX = {
# FIXME(andi): VALUES shouldn't be listed here
# 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|FROM)\b', tokens.Keyword),
+ # AS and IN are special, it may be followed by a parenthesis, but
+ # are never functions, see issue183 and issue507
+ (r'(CASE|IN|VALUES|USING|FROM|AS)\b', tokens.Keyword),
(r'(@|##|#)[A-ZÀ-Ü]\w+', tokens.Name),
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index c2d8860..34f7459 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -127,6 +127,14 @@ def test_grouping_identifier_invalid_in_middle():
assert p[3].ttype == T.Whitespace
assert str(p[2]) == 'foo.'
+@pytest.mark.parametrize('s', ['foo as (select *)', 'foo as(select *)'])
+def test_grouping_identifer_as(s):
+ # issue507
+ p = sqlparse.parse(s)[0]
+ assert isinstance(p.tokens[0], sql.Identifier)
+ token = p.tokens[0].tokens[2]
+ assert token.ttype == T.Keyword
+ assert token.normalized == 'AS'
def test_grouping_identifier_as_invalid():
# issue8