Skip to main content

split_statements

Function split_statements 

Source
pub fn split_statements(sql: &str) -> Vec<&str>
Expand description

Split a multi-statement SQL script into individual statements on top-level ;, honouring single-quoted strings (with '' escapes), double-quoted identifiers, dollar-quoted bodies ($tag$ … $tag$), line comments (--) and MySQL executable conditional comments (/*!… */ stay statement content; plain nested block comments don’t). Chunks that contain no statement content (whitespace / comments only) are dropped. PG’s simple-query protocol does this server-side; the embed path owns it here.

v7.22 (mailrs round-13 gap 1) — psql meta-command lines are dropped for client parity: a line whose first non-whitespace byte is \ BETWEEN statements (PG 18’s pg_dump wraps scripts in \restrict / \unrestrict) never reaches the parser, the same way psql consumes \-lines client-side and never sends them. A mid-statement backslash stays an ordinary byte — pg_dump only emits meta-commands between statements.