Skip to content

Commit 59033cc

Browse files
author
Andi Albrecht
committed
Fix parsing of INTO keyword in WHERE clauses (fixes andialbrecht#324).
1 parent 0ea7cf4 commit 59033cc

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Bug Fixes
1010

1111
* Fix some edge-cases when parsing invalid SQL statements.
1212
* Fix indentation of LIMIT (by romainr, issue320).
13+
* Fix parsing of INTO keyword (issue324).
1314

1415
Internal Changes
1516

sqlparse/sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ class Where(TokenList):
527527
"""A WHERE clause."""
528528
M_OPEN = T.Keyword, 'WHERE'
529529
M_CLOSE = T.Keyword, ('ORDER', 'GROUP', 'LIMIT', 'UNION', 'EXCEPT',
530-
'HAVING', 'RETURNING')
530+
'HAVING', 'RETURNING', 'INTO')
531531

532532

533533
class Case(TokenList):

tests/test_grouping.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,14 @@ def test_returning_kw_ends_where_clause():
210210
assert p.tokens[7].value == 'returning'
211211

212212

213+
def test_into_kw_ends_where_clause(): # issue324
214+
s = 'select * from foo where a = 1 into baz'
215+
p = sqlparse.parse(s)[0]
216+
assert isinstance(p.tokens[8], sql.Where)
217+
assert p.tokens[9].ttype == T.Keyword
218+
assert p.tokens[9].value == 'into'
219+
220+
213221
@pytest.mark.parametrize('sql, expected', [
214222
# note: typecast needs to be 2nd token for this test
215223
('select foo::integer from bar', 'integer'),

0 commit comments

Comments
 (0)