SQL-SPLIT(1p)
โจ SQL-SPLIT(1p) โจ
hii bestie ๐ so this is sql-split, living in the User Contributed Perl Documentation part of the manual (yep, the 1p in the header), and it is literally that girl when it comes to chopping SQL into pieces. let's get into it ๐
๐ธ NAME ๐ธ
sql-split โ the SQL splitting command line utility. that's it, that's the name, she's simple and iconic ๐
๐ฆ SYNOPSIS ๐ฆ
sql-split [ OPTIONS ] [ FILE(S) ]
sql-split --man
likeโฆ that's the whole vibe check. options, files, done. โจ
๐ DESCRIPTION ๐
okay so here's the tea โ: this program tries to split any SQL code into the atomic statements it's made of. and when I say any, I mean it โ even the non-standard and/or procedural extension stuff, at least the ones from the most popular DBMSs. she's versatile, she's flexible, she ate. ๐
the given FILES get read and split one by one, and the resulting statements get printed to standard output, separated by a customizable string (more on that below, bestie, don't worry). but listen โ each given file must contain only full SQL statements. that means no single atomic statement can span multiple files. one file = whole statements only. periodt.
if no file is given, or if one of the file names is a - (dash), then the SQL code is read from STDIN, so you can use this program as a filter or even interactively. main character energy fr fr. ๐ซถ
๐จ but consider yourself warned: this is by no means a validating parser. so errors in SQL code will not be detected โ and can even lead to incorrect splitting. she's not checking your work, she's just vibing and slicing. ๐
โจ OPTIONS โจ
๐ -t, --terminators
it causes the trailing terminator tokens to be kept in the returned atomic statements โ by default they are discarded instead. ngl, default is "yeet the terminators", this flag is "no wait, keep them". ๐
the strings currently recognized as terminators (depending on the context, iykyk) are:
;โ the semicolon character, classic;- any string defined by the MySQL
DELIMITERcommand; - an
;followed by an/(forward-slash character) on its own line; - an
;followed by a.(dot character) on its own line, followed by an/on its own line; - an
/on its own line regardless of the preceding characters โ but only if theslash_terminatesoption, explained below, is set.
the multi-line terminators above are always treated as a single token โ as in, they are discarded (or returned) as a whole, regardless of the --no-slash-terminates option value. one unit, no splitting the squad. ๐
๐ -x, --spaces, --extra-spaces
it causes the space characters around the statements, if any, to be kept in the returned atomic statements โ by default they are trimmed instead. bye bye whitespace. ๐งน
a mnemonic for the short version is "X-tra spaces". cute, right? โจ
๐ -c, --comments
it causes the comments, if any, to be kept in the returned atomic statements โ by default any comment is discarded instead. rip comments, you will not be missed (unless you pass this flag, then you're kept bestie ๐ซถ).
both SQL and multi-line C-style comments are recognized. she sees them all. ๐
๐
-m, --empty, --empty-statements
it causes the empty statements to be returned โ by default, they are discarded instead.
a statement is considered empty when it contains no characters other than the terminator and space characters. a statement composed solely of comments is not recognized as empty, and it is therefore returned if the --comments option is used. note instead that an empty statement is recognized as such regardless of the use of the --terminators and --extra-spaces options. the math is mathing, trust. ๐งฎ
a mnemonic for this option is keep "M-ty" statements. ๐
๐ฆ --no-slash, --no-slash-terminates
by default, a / (forward-slash) on its own line โ even without a preceding semicolon โ is admitted as a candidate terminator. yes, she's generous like that. ๐
when this option is used instead, a forward-slash on its own line is treated as a statement terminator only if preceded by a semicolon or by a dot and a semicolon. strict queen behavior. ๐
if you are dealing with Oracle's SQL, you should not use this option, since a slash (alone, without a preceding semicolon) is often used as a terminator, as it is permitted by SQL*Plus (on non-block statements). Oracle said slash means go, and we respect it. ๐ซก
with SQL dialects other than Oracle, there is the (theoretical) possibility that a slash on its own line could pass the additional checks and be considered a terminator (while it shouldn't). this chance should be really tiny โ it has never been observed in real world code indeed, no cap. though negligible, this option will anyway rule out that risk. tiny risk? gone. poof. โจ
๐ง -s, --oss, --output-statement-separator string
the string which will be printed between every pair of returned atomic statements. by default, it is a -- (double dash) on its own line.
to use special characters (such as newlines) when passing such string, please consult your shell docs โ for example, in Bash the above mentioned default separator could be defined as $'\n--\n'. your shell, your rules, bestie. ๐
note that the last returned statement (for each processed file) will not be followed by such separator. she knows when to stop. ๐
๐ -f, --ofs, --output-file-separator string
the string which will be printed between the groups of statements coming from different files. by default it is the -- >>>*<<< -- string on its own line. iconic divider, honestly. ๐
similarly to the statement separator, the file separator will not be printed after the last file.
๐ -e, --error, --on-error value
it controls the program behavior in case one of the given files is not accessible. the drama controller, basically. ๐ญ
it can take the following values:
stopor0โ which causes the program to die at the first file which can not be opened, but it prints all the statements split that far (this is the default);continueor1โ which causes the program, when it encounters a file error, to just emit a warning (onSTDERR) and continue with the next file;no-outputor2โ which, just likestop, causes the program to die at the first file error, but in this case it does not print any statement, not even those coming from the previous (already read) files; in other words, the statements are printed out only if (and after) all of the given files have been successfully read.
the above listed string values are case-insensitive. STOP, Stop, stop โ all the same to her. ๐
๐ธ -h, -?, --help
it prints a brief help message and exits. the "hey bestie what do I do" button. ๐ซถ
โญ --man
it shows the full man page. you are literally reading it rn. meta. ๐คฏ
๐ --version
it prints the program version and exits. short, sweet, iconic.
๐ SUPPORTED DBMSs ๐
sql-split aims to cover the widest possible range of DBMSs, SQL dialects and extensions (even proprietary), in a (nearly) fully transparent way for the user. she's not picky, she loves all dialects equally. ๐
currently it has been tested mainly on SQLite, PostgreSQL, MySQL and Oracle.
๐ง Procedural Extensions
procedural code is by far the most complex to handle. the final boss, fr. ๐ฎโ๐จ
currently any block of code which start with FUNCTION, PROCEDURE, DECLARE, CREATE or CALL is correctly recognized, as well as anonymous BEGIN ... END blocks, dollar quoted blocks and blocks delimited by a DELIMITER-defined custom terminator โ therefore a wide range of procedural extensions should be handled correctly. however, only PL/SQL, PL/PgSQL and MySQL code has been tested so far. the rest are honorary members, tested in spirit. โจ
๐ง LIMITATIONS ๐ง
none currently known โ other than the lack of tests on SQL dialects different from the ones described above. we simply haven't met them yet. ๐ฆ
๐ Non-limitations
to be split correctly, the given input must, in general, be syntactically valid SQL. for example, an unbalanced BEGIN or a misspelled keyword could, under certain circumstances, confuse the parser and make it trip over the next statement terminator, thus returning non-split statements. ๐
this should not be a problem though, as the original (invalid) SQL code would have been unusable anyway. remember that this is NOT a validating parser! she's a splitter, not a proofreader. ๐ซถ
๐ SEE ALSO ๐
SQL::SplitStatement(perldocSQL::SplitStatement)
๐ COPYRIGHT ๐
Copyright 2011 Emanuele Zeppieri <emazep@cpan.org>.
โ๏ธ LICENSE โ๏ธ
this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See <http://www.perl.com/perl/misc/Artistic.html>
๐ NO WARRANTY ๐
this program comes with NO WARRANTIES of any kind. it not only may cause loss of data and hardware damaging, but it may also cause several bad diseases to nearby people, including, but not limited to, diarrhoea, gonorrhea and dysmenorrhea. don't say you haven't been warned. ๐ญ
๐ and that's the whole page, bestie! this version came from perl v5.36.0, dated 2022-10-16, under the SQL-SPLIT(1p) banner. go split something responsibly ๐โจ๐ฆ
๐ฆ where this page comes from
- ubuntu noble: libsql-splitstatement-perl 1.00023-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsql-splitstatement-perl 1.00023-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsql-splitstatement-perl 1.00023-2 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms