summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVik <vmuriart@gmail.com>2016-06-25 07:21:58 -0700
committerGitHub <noreply@github.com>2016-06-25 07:21:58 -0700
commitdc74eb771432c73dc28cf46ac4a8b8b6d0351a94 (patch)
tree3d06ea7f5eb9aff023ab9142013b45956228c6f2
parent0e2636de12defcd2296611822d7a6ca52215c26c (diff)
parentc27a604291f7ae1d6dbf3a49376972f723ad16f1 (diff)
downloadsqlparse-dc74eb771432c73dc28cf46ac4a8b8b6d0351a94.tar.gz
Merge pull request #268 from darikg/returning
Returning clause ends where clause
-rw-r--r--sqlparse/sql.py2
-rw-r--r--tests/test_grouping.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/sqlparse/sql.py b/sqlparse/sql.py
index 4b4627f..53c16be 100644
--- a/sqlparse/sql.py
+++ b/sqlparse/sql.py
@@ -529,7 +529,7 @@ class Where(TokenList):
"""A WHERE clause."""
M_OPEN = T.Keyword, 'WHERE'
M_CLOSE = T.Keyword, ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT',
- 'HAVING')
+ 'HAVING', 'RETURNING')
class Case(TokenList):
diff --git a/tests/test_grouping.py b/tests/test_grouping.py
index 12d7310..be03110 100644
--- a/tests/test_grouping.py
+++ b/tests/test_grouping.py
@@ -188,6 +188,14 @@ def test_grouping_where():
assert isinstance(p.tokens[-1].tokens[0].tokens[-2], sql.Where)
+def test_returning_kw_ends_where_clause():
+ s = 'delete from foo where x > y returning z'
+ p = sqlparse.parse(s)[0]
+ assert isinstance(p.tokens[6], sql.Where)
+ assert p.tokens[7].ttype == T.Keyword
+ assert p.tokens[7].value == 'returning'
+
+
def test_grouping_typecast():
s = 'select foo::integer from bar'
p = sqlparse.parse(s)[0]