pglex

package
v1.153.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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

View Source
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

func IsEString(sql string, i int) bool

IsEString reports whether the quote at i opens an E'...' string, whose backslashes escape.

func IsIdentByte

func IsIdentByte(c byte) bool

IsIdentByte reports whether c may appear in an unquoted identifier.

func PasswordLiteral

func PasswordLiteral(stmt string) (object string, ok bool)

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

func RedactPasswords(sql string) string

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

func SkipComment(sql string, i int) int

SkipComment returns the index just past a comment starting at i, or i.

func SkipDollarQuoted

func SkipDollarQuoted(sql string, i int) int

SkipDollarQuoted skips $tag$ ... $tag$, or returns i when $ starts no dollar quote (a positional parameter, $1).

func SkipLexeme

func SkipLexeme(sql string, i int) int

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

func SkipString(sql string, i int, backslash bool) int

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

func Split(sql string) []string

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL