Skip to main content

split_statements

Function split_statements 

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

Split one step’s SQL into individual statements on top-level ;.

Needed because apply --dev-mode has to be able to skip a single already-applied statement rather than discarding the whole step (see migrate::apply_one). A naive split(';') would corrupt every step that contains a dollar-quoted function body — which is most of them, since trigger and constraint DDL is emitted as ... AS $$ ... ; ... $$.

Recognises the four places a ; can appear without ending a statement: single-quoted strings ('' escapes), quoted identifiers ("" escapes), dollar-quoted bodies ($$ or $tag$), and comments (-- to end of line, /* */ which nest in PostgreSQL). Empty statements are dropped, so a trailing ; or a stray blank line never produces one.