diff options
| -rw-r--r-- | CHANGELOG | 1 | ||||
| -rw-r--r-- | sqlparse/engine/grouping.py | 2 | ||||
| -rw-r--r-- | tests/test_regressions.py | 10 |
3 files changed, 12 insertions, 1 deletions
@@ -12,6 +12,7 @@ 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). +* Fix handling of semicolon in assignments (issue359, issue358). diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index 6684c13..fa87c9f 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -134,7 +134,7 @@ def group_assignment(tlist): return token.match(T.Assignment, ':=') def valid(token): - return token is not None + return token is not None and token.ttype not in (T.Keyword) def post(tlist, pidx, tidx, nidx): m_semicolon = T.Punctuation, ';' diff --git a/tests/test_regressions.py b/tests/test_regressions.py index cc553c2..89828f0 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -356,3 +356,13 @@ def test_issue322_concurrently_is_keyword(): assert p.tokens[4].value == 'CONCURRENTLY' assert isinstance(p.tokens[6], sql.Identifier) assert p.tokens[6].value == 'myindex' + + +@pytest.mark.parametrize('s', [ + 'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop;', + 'SELECT @min_price:=MIN(price), @max_price:=MAX(price) FROM shop', + +]) +def test_issue359_index_error_assignments(s): + sqlparse.parse(s) + sqlparse.format(s, strip_comments=True) |
