diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2014-01-28 15:16:12 +0100 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2014-01-28 15:16:12 +0100 |
commit | d74ea26ec3a7f189ec00f6b949fd95082ba5b204 (patch) | |
tree | 3253f7718a98a230f6d6a715150f9a46e3e80d31 | |
parent | ff6371f67540c03e7400ffa7a5a6bd8b48c0e2d6 (diff) | |
download | sqlparse-d74ea26ec3a7f189ec00f6b949fd95082ba5b204.tar.gz |
Fix parsing and formatting of statements containing EXCEPT keyword.
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
-rw-r--r-- | sqlparse/filters.py | 2 | ||||
-rw-r--r-- | tests/test_regressions.py | 15 |
4 files changed, 18 insertions, 2 deletions
@@ -5,6 +5,7 @@ Bug Fixes * Fix incorrect parsing of string literals containing line breaks (issue118). * Fix typo in keywords, add MERGE, COLLECT keywords (issue122/124, by Cristian Orellana). * Improve parsing of string literals in columns. +* Fix parsing and formatting of statements containing EXCEPT keyword. Enhancements * Classify DML keywords (issue116, by Victor Hahn). diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 44cc124..c11e5f0 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -297,7 +297,7 @@ def group_where(tlist): if not isinstance(sgroup, sql.Where)] idx = 0 token = tlist.token_next_match(idx, T.Keyword, 'WHERE') - stopwords = ('ORDER', 'GROUP', 'LIMIT', 'UNION') + stopwords = ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT') while token: tidx = tlist.token_index(token) end = tlist.token_next_match(tidx + 1, T.Keyword, stopwords) diff --git a/sqlparse/filters.py b/sqlparse/filters.py index 337d3bf..40caf51 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -301,7 +301,7 @@ class ReindentFilter: def _split_kwds(self, tlist): split_words = ('FROM', 'STRAIGHT_JOIN$', 'JOIN$', 'AND', 'OR', 'GROUP', 'ORDER', 'UNION', 'VALUES', - 'SET', 'BETWEEN') + 'SET', 'BETWEEN', 'EXCEPT') def _next_token(i): t = tlist.token_next_match(i, T.Keyword, split_words, diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 423f2d6..395c2b6 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -218,3 +218,18 @@ def test_issue90(): ' "price" = 1,', ' "description" = NULL']) assert formatted == tformatted + + +def test_except_formatting(): + sql = 'SELECT 1 FROM foo WHERE 2 = 3 EXCEPT SELECT 2 FROM bar WHERE 1 = 2' + formatted = sqlparse.format(sql, reindent=True) + tformatted = '\n'.join([ + 'SELECT 1', + 'FROM foo', + 'WHERE 2 = 3', + 'EXCEPT', + 'SELECT 2', + 'FROM bar', + 'WHERE 1 = 2' + ]) + assert formatted == tformatted |