Skip to content

Commit

Permalink
Handle operator grouping after identifying typecasts (fixes #297).
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Oct 1, 2016
1 parent 08862d2 commit f0754a6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion sqlparse/engine/grouping.py
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions tests/test_grouping.py
Expand Up @@ -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)
Expand Down

0 comments on commit f0754a6

Please sign in to comment.