Skip to content

Commit dff274c

Browse files
committed
Re-order parsing so that comparisons are seens as identifiers (fixes andialbrecht#327).
1 parent 7f8846b commit dff274c

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

CHANGELOG

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
Development Version
22
-------------------
33

4-
Nothing yet.
4+
Bug Fixes
5+
6+
* Fix detection of identifiers using comparisons (issue327).
57

68

79
Release 0.2.3 (Mar 02, 2017)

sqlparse/engine/grouping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def group_where(tlist):
274274
@recurse()
275275
def group_aliased(tlist):
276276
I_ALIAS = (sql.Parenthesis, sql.Function, sql.Case, sql.Identifier,
277-
sql.Operation)
277+
sql.Operation, sql.Comparison)
278278

279279
tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number)
280280
while token:
@@ -346,10 +346,10 @@ def group(stmt):
346346
group_order,
347347
group_typecasts,
348348
group_operator,
349+
group_comparison,
349350
group_as,
350351
group_aliased,
351352
group_assignment,
352-
group_comparison,
353353

354354
align_comments,
355355
group_identifier_list,

tests/test_grouping.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ def test_grouping_identifiers():
6464
assert identifiers[0].get_alias() == "col"
6565

6666

67+
@pytest.mark.parametrize('s', [
68+
'1 as f',
69+
'foo as f',
70+
'foo f',
71+
'1/2 as f',
72+
'1/2 f',
73+
'1<2 as f', # issue327
74+
'1<2 f',
75+
])
76+
def test_simple_identifiers(s):
77+
parsed = sqlparse.parse(s)[0]
78+
assert isinstance(parsed.tokens[0], sql.Identifier)
79+
80+
6781
@pytest.mark.parametrize('s', [
6882
'foo, bar',
6983
'sum(a), sum(b)',

0 commit comments

Comments
 (0)