Documentation ¶
Index ¶
- Constants
- Variables
- func Split(sql io.Reader, transform ...func(string) string) (stats []string, err error)
- func SplitAndTrim(sql io.Reader) (stats []string, err error)
- type AtomicState
- type BlockState
- type CommentState
- type DollarState
- type EscapeState
- type QuoteState
- type ReadyState
- type State
- type TagState
Constants ¶
const ( // Omit BEGIN to allow arbitrary whitespaces between BEGIN and ATOMIC keywords. // This can fail if ATOMIC is used as column name because it is not a reserved // keyword: https://www.postgresql.org/docs/current/sql-keywords-appendix.html BEGIN_ATOMIC = "ATOMIC" END_ATOMIC = "END" )
Variables ¶
var MaxScannerCapacity = 256 * 1024
MaxScannerCapacity defaults to 64 * 1024 which is not enough for certain lines containing e.g. geographical data. 256K ought to be enough for anybody...
Functions ¶
func Split ¶
Use bufio.Scanner to split a PostgreSQL string into multiple statements.
The core problem is to figure out whether the current ; separator is inside an escaped string literal. PostgreSQL has multiple ways of opening a string literal, $$, ', --, /*, etc. We use a FSM to guarantee these states are entered exclusively. If not in one of the above escape states, the next ; token can be parsed as statement separator.
Each statement is split as it is, without removing comments or white spaces.
Types ¶
type AtomicState ¶
type AtomicState struct {
// contains filtered or unexported fields
}
Opened BEGIN ATOMIC function body
type BlockState ¶
type BlockState struct {
// contains filtered or unexported fields
}
Opened a block comment
type DollarState ¶
type DollarState struct {
// contains filtered or unexported fields
}
Opened a dollar quote, no characters are ever esacped.
type QuoteState ¶
type QuoteState struct {
// contains filtered or unexported fields
}
Opened a single quote ' or double quote "