Documentation
¶
Overview ¶
Package pgregress provides tools for running PostgreSQL regression test SQL files against the pgparser parser to verify parse compatibility.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ContainsPsqlVariable ¶
ContainsPsqlVariable detects psql variable interpolation patterns in SQL text. These patterns (:varname, :'varname', :"varname") are expanded by the psql client before being sent to the server, so they are not valid SQL and cannot be parsed by a standard SQL parser.
The function uses a best-effort approach: it scans through the SQL text tracking string literal context (single-quoted, double-quoted, dollar-quoted) and comments to avoid false positives from colons inside strings or comments. It correctly skips :: (PostgreSQL type cast) and := (PL/pgSQL assignment).
func ReplacePsqlVariables ¶
ReplacePsqlVariables replaces psql variable interpolation patterns with valid SQL placeholders, allowing the statement to be parsed for grammar checking. Returns the sanitized SQL and true if any replacements were made.
Replacements:
:varname -> psql_var :'varname' -> 'psql_var' :"varname" -> "psql_var"
Types ¶
type ExtractedStmt ¶
type ExtractedStmt struct {
SQL string // The complete SQL text (without trailing semicolon)
File string // Source filename (basename)
StartLine int // 1-based line number where this statement starts
HasPsqlVar bool // True if the statement contains psql variable interpolation
}
ExtractedStmt represents a single SQL statement extracted from a .sql file.
func ExtractStatements ¶
func ExtractStatements(filename string, content []byte) []ExtractedStmt
ExtractStatements splits a PostgreSQL regression test .sql file into individual SQL statements. It handles psql metacommands, dollar-quoted strings, COPY FROM stdin data blocks, and all PostgreSQL string literal forms.