pglex

package
v1.166.3 Latest Latest
Warning

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

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

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 FirstWord added in v1.153.2

func FirstWord(sql string) string

FirstWord is the lowercased first word of sql after whitespace, comments and opening parentheses: the keyword a statement is read by.

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, in the statement itself or in a statement of a dollar-quoted body it carries (a DO block, a function's body). 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.

A statement that sets no password itself has each dollar-quoted body it carries read the same way, so a role created inside a DO block or a function's body is redacted as one created at the top level.

func RunsConcurrently added in v1.153.2

func RunsConcurrently(sql string) bool

RunsConcurrently reports whether sql holds a CREATE, DROP or REINDEX statement with the word CONCURRENTLY outside its literals and comments, which PostgreSQL runs only outside a transaction block (#2490).

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