diff options
author | Andi Albrecht <albrecht.andi@gmail.com> | 2014-03-03 07:55:06 +0100 |
---|---|---|
committer | Andi Albrecht <albrecht.andi@gmail.com> | 2014-03-03 07:55:06 +0100 |
commit | e6d86edf4454153c655ba548b5698a4dbe5a10fd (patch) | |
tree | 7319c7bdffffcc83946d6ba2312e7ea33947f233 | |
parent | fcf41c86cd0f1370a5f77ffa83334c803e82157f (diff) | |
download | sqlparse-e6d86edf4454153c655ba548b5698a4dbe5a10fd.tar.gz |
Improve handling of NULL in aliased identifiers.
-rw-r--r-- | CHANGES | 7 | ||||
-rw-r--r-- | sqlparse/engine/grouping.py | 3 | ||||
-rw-r--r-- | tests/test_regressions.py | 11 |
3 files changed, 21 insertions, 0 deletions
@@ -1,3 +1,10 @@ +Development Version +------------------- + +Bug Fixes +* Fix handling of NULL keywords in aliased identifiers. + + Release 0.1.11 (Feb 07, 2014) ----------------------------- diff --git a/sqlparse/engine/grouping.py b/sqlparse/engine/grouping.py index c11e5f0..bd97f41 100644 --- a/sqlparse/engine/grouping.py +++ b/sqlparse/engine/grouping.py @@ -117,6 +117,8 @@ def group_as(tlist): return not token.ttype in (T.DML, T.DDL) def _left_valid(token): + if token.ttype is T.Keyword and token.value in ('NULL'): + return True return token.ttype is not T.Keyword _group_left_right(tlist, T.Keyword, 'AS', sql.Identifier, @@ -233,6 +235,7 @@ def group_identifier_list(tlist): lambda t: t.ttype == T.Keyword, lambda t: isinstance(t, sql.Comparison), lambda t: isinstance(t, sql.Comment), + lambda t: t.ttype == T.Comment.Multiline, ] tcomma = tlist.token_next_match(idx, T.Punctuation, ',') start = None diff --git a/tests/test_regressions.py b/tests/test_regressions.py index 395c2b6..e30ddf0 100644 --- a/tests/test_regressions.py +++ b/tests/test_regressions.py @@ -233,3 +233,14 @@ def test_except_formatting(): 'WHERE 1 = 2' ]) assert formatted == tformatted + + +def test_null_with_as(): + sql = 'SELECT NULL AS c1, NULL AS c2 FROM t1' + formatted = sqlparse.format(sql, reindent=True) + tformatted = '\n'.join([ + 'SELECT NULL AS c1,', + ' NULL AS c2', + 'FROM t1' + ]) + assert formatted == tformatted
\ No newline at end of file |