Skip to main content

Module plpgsql

Module plpgsql 

Source
Expand description

PL/pgSQL function bodies: typed AST, parser, and the variable binding rewriter.

Bodies are parsed with libpg_query’s PL/pgSQL parser (pg_query::parse_plpgsql), which returns the same JSON dump PostgreSQL itself produces. This module lowers that JSON into a typed AST whose embedded SQL fragments are pre-compiled into Expr / Statement values, ready for execution against the engine.

Variable references inside embedded SQL are plain column references after compilation. At execution time the interpreter rewrites them into literals through VariableResolver / bind_expr / bind_statement before handing the statement to the engine. This matches plpgsql.variable_conflict = use_variable resolution: a name that is both a PL/pgSQL variable and a column of a queried table resolves to the variable (stock PostgreSQL raises an ambiguity error instead).

Structs§

PLpgSQLBlock
[DECLARE ...] BEGIN ... [EXCEPTION ...] END block.
PLpgSQLCursor
PLpgSQLCursorArgument
PLpgSQLExceptionArm
One WHEN cond [OR cond ...] THEN stmts arm of an exception section.
PLpgSQLFunction
A parsed PL/pgSQL function body: the flat datum table plus the outermost block.
PLpgSQLRowField
name -> datum slot of a row target.
PLpgSQLVar
Scalar PL/pgSQL variable (declared variable, parameter, loop counter, or an internal compiler temporary).

Enums§

IntoTarget
Assignment / INTO target.
PLpgSQLDatum
One entry in the function’s flat datum table. varno / dno references inside statements index into this table.
PLpgSQLReturnValue
Value source for RETURN and RETURN NEXT. PostgreSQL 18 stores a simple datum reference in retvarno, distinct from a general SQL expression.
PLpgSQLStmt
Executable PL/pgSQL statement.
RaiseLevel
RAISE severity.

Traits§

VariableResolver
Resolves routine variables while a compiled expression / statement is being specialized for one execution.

Functions§

bind_expr
Rewrite an expression, substituting resolvable variable references with literals. References the resolver declines stay untouched.
bind_select
Rewrite a SELECT body, substituting resolvable variables.
bind_statement
Rewrite a full statement, substituting resolvable variables in every expression position. Statements without expression payloads pass through unchanged.
compile_expression_text
Compile a bare expression through PostgreSQL’s PL/pgSQL expression parser.
condition_sqlstate
Map a PL/pgSQL condition name to the SQLSTATE used by RAISE condition_name.
condition_sqlstates
Return every SQLSTATE matched by a PL/pgSQL exception condition.
parse_do_block
Parse a DO $$ ... $$ body by wrapping it into an anonymous void-returning function.
parse_function