diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2016-10-01 14:07:52 +0200 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2016-10-01 14:07:52 +0200 |
commit | f0754a6b6540e37c8aa270975194101024d4b2f8 (patch) | |
tree | 3464acf94cef7178d766ed66f8ed79593042a199 | |
parent | 08862d24091faa2bfe80972df142e12575b7790c (diff) | |
download | sqlparse-f0754a6b6540e37c8aa270975194101024d4b2f8.tar.gz |
Handle operator grouping after identifying typecasts (fixes #297).
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
-rw-r--r-- | tests/test_grouping.py | 14 |
3 files changed, 16 insertions, 1 deletions
@@ -11,6 +11,7 @@ Bug Fixes * Fix parsing of incomplete AS (issue284, by vmuriart). * Fix parsing of Oracle names containing dollars (issue291). * Fix parsing of UNION ALL (issue294). +* Fix grouping of identifiers containing typecasts (issue297). Internal Changes diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index bae3e24..5fa3909 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -343,9 +343,9 @@ def group(stmt): group_period, group_arrays, group_identifier, - group_operator, group_order, group_typecasts, + group_operator, group_as, group_aliased, group_assignment, diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 655ef0f..20151a1 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -64,6 +64,20 @@ def test_grouping_identifiers(): assert identifiers[0].get_alias() == "col" +@pytest.mark.parametrize('s', [ + 'foo, bar', + 'sum(a), sum(b)', + 'sum(a) as x, b as y', + 'sum(a)::integer, b', + 'sum(a)/count(b) as x, y', + 'sum(a)::integer as x, y', + 'sum(a)::integer/count(b) as x, y', # issue297 +]) +def test_group_identifier_list(s): + parsed = sqlparse.parse(s)[0] + assert isinstance(parsed.tokens[0], sql.IdentifierList) + + def test_grouping_identifier_wildcard(): p = sqlparse.parse('a.*, b.id')[0] assert isinstance(p.tokens[0], sql.IdentifierList) |