From ee2950c297ef4e2ec61a1138ca78426b9bf91881 Mon Sep 17 00:00:00 2001 From: Guillermo Date: Sun, 23 Aug 2026 18:09:03 +0200 Subject: [PATCH] Treat the GO batch separator case-insensitively when splitting The lexer compiles every pattern with re.IGNORECASE, and is_keyword uppercases only for the dictionary lookup and returns the original spelling, so a lowercase "go" reaches the splitter as (T.Keyword, 'go'). StatementSplitter.process compared that raw value against 'GO', so lowercase and mixed-case batch separators did not split and their batches were merged into the following statement. Every other keyword comparison in the class normalises through value.upper(). This makes that one consistent, and adds case-varied parameters to test_split_go. --- sqlparse/engine/statement_splitter.py | 2 +- tests/test_split.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sqlparse/engine/statement_splitter.py b/sqlparse/engine/statement_splitter.py index bc57d170..5db9c9bf 100644 --- a/sqlparse/engine/statement_splitter.py +++ b/sqlparse/engine/statement_splitter.py @@ -182,7 +182,7 @@ def process(self, stream): # Split on semicolon if not inside a BEGIN...END block if self.level <= 0 and 'BEGIN' not in self._block_stack: self.consume_ws = True - elif ttype is T.Keyword and value.split()[0] == 'GO': + elif ttype is T.Keyword and value.upper().split()[0] == 'GO': self.consume_ws = True elif (ttype not in (T.Whitespace, T.Newline, T.Comment.Single, T.Comment.Multiline) diff --git a/tests/test_split.py b/tests/test_split.py index 92c3fefe..8a241c93 100644 --- a/tests/test_split.py +++ b/tests/test_split.py @@ -198,7 +198,12 @@ def test_split_strip_semicolon_procedure(load_file): @pytest.mark.parametrize('sql, num', [ ('USE foo;\nGO\nSELECT 1;\nGO', 4), ('SELECT * FROM foo;\nGO', 2), - ('USE foo;\nGO 2\nSELECT 1;', 3) + ('USE foo;\nGO 2\nSELECT 1;', 3), + # issue762: the batch separator is case-insensitive + ('USE foo;\ngo\nSELECT 1;\ngo', 4), + ('USE foo;\nGo\nSELECT 1;\nGo', 4), + ('SELECT * FROM foo;\ngo', 2), + ('USE foo;\ngo 2\nSELECT 1;', 3), ]) def test_split_go(sql, num): # issue762 stmts = sqlparse.split(sql)