summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2017-07-29 10:16:34 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2017-07-29 10:16:34 +0200
commit113897280c612aa839fa9f8bd44bfd720d3729c7 (patch)
treea1cb725d8525f0618441887eefe12f0ceb6248b5
parentdc788ab5b1af2e2a4a988b31a09d8d6656853f76 (diff)
downloadsqlparse-113897280c612aa839fa9f8bd44bfd720d3729c7.tar.gz
Fix parsing of UNION ALL after WHERE (fixes #349).
-rw-r--r--CHANGELOG2
-rw-r--r--sqlparse/sql.py5
-rw-r--r--tests/test_grouping.py9
3 files changed, 14 insertions, 2 deletions
diff --git a/CHANGELOG b/CHANGELOG
index c61b3d8..83c5043 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,8 @@ Bug Fixes
* Fix parsing of MySQL table names starting with digits (issue337).
* Fix detection of identifiers using comparisons (issue327).
+* Fix parsing of UNION ALL after WHERE (issue349).
+
Release 0.2.3 (Mar 02, 2017)
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index f190de8..f698782 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -526,8 +526,9 @@ class Comment(TokenList):
class Where(TokenList):
"""A WHERE clause."""
M_OPEN = T.Keyword, 'WHERE'
- M_CLOSE = T.Keyword, ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT',
- 'HAVING', 'RETURNING', 'INTO')
+ M_CLOSE = T.Keyword, (
+ 'ORDER', 'GROUP', 'LIMIT', 'UNION', 'UNION ALL', 'EXCEPT',
+ 'HAVING', 'RETURNING', 'INTO')
class Case(TokenList):
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 76ba651..1f3a19e 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -216,6 +216,15 @@ def test_grouping_where():
assert isinstance(p.tokens[-1].tokens[0].tokens[-2], sql.Where)
+@pytest.mark.parametrize('s', (
+ 'select 1 where 1 = 2 union select 2',
+ 'select 1 where 1 = 2 union all select 2',
+))
+def test_grouping_where_union(s):
+ p = sqlparse.parse(s)[0]
+ assert p.tokens[5].value.startswith('union')
+
+
def test_returning_kw_ends_where_clause():
s = 'delete from foo where x > y returning z'
p = sqlparse.parse(s)[0]