Expand description
Split a SQL document on top-level semicolons.
Why we slice ourselves rather than letting the parser do it: sqlparser
aborts on the first syntax error, which would poison the rest of the
file. By slicing first and feeding each piece in independently we
contain failures to a single statement and keep editing other parts of
the file fully analysed.
Edge cases handled:
- Single-quoted strings: semicolons inside are part of the literal.
- Double-quoted identifiers: same.
- Postgres dollar-quoted blocks:
$tag$ ... $tag$(any tag, including the empty tag$$ ... $$). - Backslash escapes inside quoted strings.
Line comments (-- to end-of-line) and block comments (/* ... */,
including nested PG-style blocks) are stripped for the purpose of
finding statement boundaries. A ; inside a comment must not
split the statement, otherwise the body fragment after ; parses
as broken SQL and produces a sql000 syntax error.
Functionsยง
- split_
statements - Returns
(trimmed_chunk, range_in_source)for each top-level statement. Whitespace-only chunks are dropped.