summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2017-04-18 08:50:50 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2017-04-18 08:50:50 +0200
commitdff274ca46e8a38b2f1615b99a799e3266dc8c5e (patch)
tree84848d6adf443e406917e50f4301e605b3968631
parent7f8846b43aca5994983651bbcbe18f22386358fe (diff)
downloadsqlparse-dff274ca46e8a38b2f1615b99a799e3266dc8c5e.tar.gz
Re-order parsing so that comparisons are seens as identifiers (fixes #327).
-rw-r--r--CHANGELOG4
-rw-r--r--sqlparse/engine/grouping.py4
-rw-r--r--tests/test_grouping.py14
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
@@ -65,6 +65,20 @@ def test_grouping_identifiers():
@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)',
'sum(a) as x, b as y',