From dff274ca46e8a38b2f1615b99a799e3266dc8c5e Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Tue, 18 Apr 2017 08:50:50 +0200 Subject: Re-order parsing so that comparisons are seens as identifiers (fixes #327). --- CHANGELOG | 4 +++- sqlparse/engine/grouping.py | 4 ++-- tests/test_grouping.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index d0ba7ed..ecd075a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,7 +1,9 @@ Development Version ------------------- -Nothing yet. +Bug Fixes + +* Fix detection of identifiers using comparisons (issue327). Release 0.2.3 (Mar 02, 2017) diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 3c49201..6684c13 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -274,7 +274,7 @@ def group_where(tlist): @recurse() def group_aliased(tlist): I_ALIAS = (sql.Parenthesis, sql.Function, sql.Case, sql.Identifier, - sql.Operation) + sql.Operation, sql.Comparison) tidx, token = tlist.token_next_by(i=I_ALIAS, t=T.Number) while token: @@ -346,10 +346,10 @@ def group(stmt): group_order, group_typecasts, group_operator, + group_comparison, group_as, group_aliased, group_assignment, - group_comparison, align_comments, group_identifier_list, diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 72f94f6..76ba651 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', [ + '1 as f', + 'foo as f', + 'foo f', + '1/2 as f', + '1/2 f', + '1<2 as f', # issue327 + '1<2 f', +]) +def test_simple_identifiers(s): + parsed = sqlparse.parse(s)[0] + assert isinstance(parsed.tokens[0], sql.Identifier) + + @pytest.mark.parametrize('s', [ 'foo, bar', 'sum(a), sum(b)', -- cgit v1.2.1