Documentation
¶
Overview ¶
Package pglex reads PostgreSQL SQL text lexically: where its top-level statements end, and where a string literal, a quoted identifier, a dollar-quoted body or a comment starts and stops. It parses nothing; the application database kind's statement checks, its migration lint and the admin console's statement lists read SQL through it (#2410, #2427).
Index ¶
- Constants
- func IsEString(sql string, i int) bool
- func IsIdentByte(c byte) bool
- func PasswordLiteral(stmt string) (object string, ok bool)
- func RedactPasswords(sql string) string
- func SkipComment(sql string, i int) int
- func SkipDollarQuoted(sql string, i int) int
- func SkipLexeme(sql string, i int) int
- func SkipString(sql string, i int, backslash bool) int
- func Split(sql string) []string
Constants ¶
const RedactedLiteral = "'[REDACTED]'"
RedactedLiteral is what RedactPasswords writes in place of a password literal: a string literal still, so the statement reads as SQL.
Variables ¶
This section is empty.
Functions ¶
func IsEString ¶
IsEString reports whether the quote at i opens an E'...' string, whose backslashes escape.
func IsIdentByte ¶
IsIdentByte reports whether c may appear in an unquoted identifier.
func PasswordLiteral ¶
PasswordLiteral reports whether stmt, one statement, writes a credential: a role, user, group or user mapping given a PASSWORD other than NULL. It returns the object the statement acts on ("CREATE ROLE"). The migration review's password_literal rule and RedactPasswords both read a statement by it, so what the review refuses is what a stored copy has redacted.
func RedactPasswords ¶
RedactPasswords returns sql with every literal after the PASSWORD of a statement PasswordLiteral reports replaced by RedactedLiteral, and any other text as it is. Every literal after the PASSWORD is replaced, not only the first: what follows it (VALID UNTIL, a user mapping's later options) is read no further than that.
func SkipComment ¶
SkipComment returns the index just past a comment starting at i, or i.
func SkipDollarQuoted ¶
SkipDollarQuoted skips $tag$ ... $tag$, or returns i when $ starts no dollar quote (a positional parameter, $1).
func SkipLexeme ¶
SkipLexeme returns the index just past the literal, quoted identifier, dollar-quoted body or comment starting at i, or i when none starts there. One that never ends runs to the end of sql.
func SkipString ¶
SkipString skips a quoted run where a doubled quote is an escaped one and, in an E-string, a backslash escapes the next byte.
func Split ¶
Split cuts SQL into its top-level statements at the semicolons that end them, skipping a semicolon inside a string literal (with an E-string's backslash escapes), a quoted identifier, a dollar-quoted body (a function's, a DO block's), a comment, or a SQL-standard function body (BEGIN ATOMIC ... END, whose statements end in semicolons of their own). Each statement is trimmed; an empty one is dropped.
Types ¶
This section is empty.