plpgsqlast

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 4 Imported by: 1 module, 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

Copyright 2025 Supabase, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2025 Supabase, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Package plpgsqlast holds the PL/pgSQL AST: the node hierarchy produced by the PL/pgSQL parser in go/common/parser/plpgsql. It is deliberately a SEPARATE hierarchy from the SQL AST in go/common/parser/ast — mirroring PostgreSQL, where PLpgSQL_stmt/PLpgSQL_expr are distinct from the SQL parse tree.

Keeping these nodes out of package ast keeps the ~49-type PL/pgSQL vocabulary (and its generated clone/rewrite helpers) from bloating the SQL AST's central generated files and NodeTag enum. The two hierarchies meet at the embedded SQL boundary: a PL/pgSQL expression node holds an ast.Stmt for its parsed SQL fragment, which the gateway hands to the SQL-side analysis. Dependencies flow one way (plpgsqlast -> ast), so there is no import cycle.

Index

Constants

View Source
const (
	CURSOR_OPT_SCROLL    = 0x0002
	CURSOR_OPT_NO_SCROLL = 0x0004
	CURSOR_OPT_FAST_PLAN = 0x0100
)

Cursor option bits. Only the flags PG's plpgsql parser sets are carried: the syntactic SCROLL / NO SCROLL, and the fixed FAST_PLAN default it applies to every OPEN / cursor declaration. Ported from postgres/src/include/nodes/parsenodes.h:3281-3291

View Source
const FETCH_ALL int64 = 1<<63 - 1

FETCH_ALL is the HowMany sentinel for `FETCH ALL` / `MOVE ALL`. Ported from postgres/src/include/nodes/parsenodes.h:3326 (FETCH_ALL = LONG_MAX).

Variables

This section is empty.

Functions

func CloneSliceOfInt

func CloneSliceOfInt(n []int) []int

CloneSliceOfInt creates a deep clone of the input.

func CloneSliceOfString

func CloneSliceOfString(n []string) []string

CloneSliceOfString creates a deep clone of the input.

func IsSQLStateCode

func IsSQLStateCode(s string) bool

IsSQLStateCode reports whether s has the shape of a SQLSTATE code: exactly five characters, each a digit or an uppercase A–Z (PG's length + charset check). It is the parse-time validator for `SQLSTATE 'xxxxx'` and, because a lowercased condition name never matches it, the deparse-time discriminator between the SQLSTATE and named-condition WHEN forms.

Types

type ApplyFunc

type ApplyFunc func(*Cursor) bool

An ApplyFunc is invoked by Rewrite for each node n, even if n is nil, before and/or after the node's children, using a Cursor describing the current node and providing operations on it.

The return value of ApplyFunc controls the syntax tree traversal. See Rewrite for details.

type BaseNode

type BaseNode struct {
	Tag NodeTag // Node type tag
	Loc int     // Source location in bytes (-1 if unavailable)
}

BaseNode is embedded by every PL/pgSQL node to supply the common tag and location plumbing, mirroring ast.BaseNode.

func CloneBaseNode

func CloneBaseNode(n BaseNode) BaseNode

CloneBaseNode creates a deep clone of the input.

func CloneRefOfBaseNode

func CloneRefOfBaseNode(n *BaseNode) *BaseNode

CloneRefOfBaseNode creates a deep clone of the input.

func (*BaseNode) Location

func (n *BaseNode) Location() int

Location returns the node's source location.

func (*BaseNode) NodeTag

func (n *BaseNode) NodeTag() NodeTag

NodeTag returns the node's type tag.

func (*BaseNode) SetLocation

func (n *BaseNode) SetLocation(location int)

SetLocation sets the node's source location.

func (*BaseNode) SqlString

func (n *BaseNode) SqlString() string

SqlString provides a default that panics; concrete node types override it to deparse themselves.

func (*BaseNode) String

func (n *BaseNode) String() string

String returns a basic string representation.

type Cursor

type Cursor struct {
	// contains filtered or unexported fields
}

A Cursor describes a node encountered during Rewrite. Information about the node and its parent is available from the Node and Parent methods.

func (*Cursor) Node

func (c *Cursor) Node() Node

Node returns the current Node.

func (*Cursor) Parent

func (c *Cursor) Parent() Node

Parent returns the parent of the current Node.

func (*Cursor) Replace

func (c *Cursor) Replace(newNode Node)

Replace replaces the current node in the parent field with this new object. The caller needs to make sure to not replace the object with something of the wrong type, or the visitor will panic.

func (*Cursor) ReplaceAndRevisit

func (c *Cursor) ReplaceAndRevisit(newNode Node)

ReplaceAndRevisit replaces the current node in the parent field with this new object. When used, this will abort the visitation of the current node — no post or children visited, and the new node visited.

type Datum

type Datum interface {
	Node

	// DatumNo returns the datum's dno (index in the function's datum list).
	DatumNo() int
	// SetDatumNo records the datum's dno when it is appended to the datum list.
	SetDatumNo(dno int)
	// contains filtered or unexported methods
}

Datum is implemented by every PL/pgSQL datum — the Go analogue of PG's PLpgSQL_datum supertype (postgres/src/pl/plpgsql/src/plpgsql.h). A datum carries a dno: its index in the function's flat datum list. The scanner resolves an identifier to a datum and emits T_DATUM carrying it, and the namespace points back at the datum by that dno.

The concrete datums are PLpgSQL_var (a scalar), PLpgSQL_rec (a record — the RECORD / %ROWTYPE cases we can recognize syntactically), PLpgSQL_row (a transient scalar list behind a comma-separated targetlist), PLpgSQL_recfield (a rec.field reference), and PLpgSQL_alias. Code branches on the concrete Go type rather than a PG-style dtype tag. What we still cannot classify is a variable declared with a *named composite type*: telling it from a scalar needs the system catalog, so it stays a PLpgSQL_var (and `that_var.field` resolves as text rather than a RECFIELD).

func CloneDatum

func CloneDatum(in Datum) Datum

CloneDatum creates a deep clone of the input.

func CloneSliceOfDatum

func CloneSliceOfDatum(n []Datum) []Datum

CloneSliceOfDatum creates a deep clone of the input.

type FetchDirection

type FetchDirection int

FetchDirection is the direction of a FETCH/MOVE. For ABSOLUTE/RELATIVE the count is an expression (Expr); for the others it is HowMany. Ported from postgres/src/include/nodes/parsenodes.h:3316-3324

const (
	FETCH_FORWARD FetchDirection = iota
	FETCH_BACKWARD
	FETCH_ABSOLUTE
	FETCH_RELATIVE
)

type Node

type Node interface {
	// NodeTag returns the type tag for this node.
	NodeTag() NodeTag

	// Location returns the byte offset in the source where this node begins,
	// or -1 if unavailable.
	Location() int

	// SetLocation records the byte offset in the source where this node begins.
	SetLocation(location int)

	// String returns a string representation of the node (for debugging).
	String() string

	// SqlString returns the PL/pgSQL source representation of this node, to
	// support round-tripping a parsed body back to text.
	SqlString() string
}

Node is implemented by every PL/pgSQL AST node. It mirrors ast.Node so the two hierarchies feel the same to callers, but it is a separate interface so PL/pgSQL nodes are never accepted by the SQL AST's clone/rewrite machinery (and vice versa) — they get their own generated helpers instead.

func CloneNode

func CloneNode(in Node) Node

Code generated by asthelpergen. DO NOT EDIT. CloneNode creates a deep clone of the input.

func Rewrite

func Rewrite(node Node, pre, post ApplyFunc) (result Node)

Rewrite traverses a PL/pgSQL syntax tree recursively, starting with root, and calling pre and post for each node as described below. Rewrite returns the syntax tree, possibly modified.

If pre is not nil, it is called for each node before the node's children are traversed (pre-order). If pre returns false, no children are traversed, and post is not called for that node.

If post is not nil, and a prior call of pre didn't return false, post is called for each node after its children are traversed (post-order). If post returns false, traversal is terminated and Rewrite returns immediately.

Only fields that refer to PL/pgSQL nodes are considered children; basic fields and fields from other AST hierarchies (notably PLpgSQL_expr.Parsed, an ast.Stmt) are not traversed. The embedded SQL is analyzed separately.

Example usage:

// Find every embedded SQL fragment in a parsed body.
var exprs []*PLpgSQL_expr
Rewrite(fn, func(cursor *Cursor) bool {
    if e, ok := cursor.Node().(*PLpgSQL_expr); ok {
        exprs = append(exprs, e)
    }
    return true // continue traversal
}, nil)

type NodeTag

type NodeTag int

NodeTag identifies the concrete type of a PL/pgSQL AST node. It is independent of ast.NodeTag — the two hierarchies have separate tag spaces.

const (
	// T_Invalid is the zero value; it marks an uninitialized or placeholder node.
	T_Invalid                   NodeTag = iota
	T_PLpgSQL_function                  // Root of a parsed PL/pgSQL function body
	T_PLpgSQL_stmt_block                // BEGIN … END block
	T_PLpgSQL_expr                      // SQL fragment (verbatim text + parsed AST)
	T_PLpgSQL_exception_block           // EXCEPTION section of a block
	T_PLpgSQL_var                       // declared scalar variable
	T_PLpgSQL_rec                       // record variable (RECORD / %ROWTYPE)
	T_PLpgSQL_row                       // scalar list (comma-separated targetlist / INTO)
	T_PLpgSQL_recfield                  // field reference into a record (rec.field)
	T_PLpgSQL_type                      // declared type (captured as text)
	T_PLpgSQL_stmt_assign               // assignment statement (target := expr)
	T_PLpgSQL_stmt_if                   // IF … THEN … [ELSIF …] [ELSE …] END IF
	T_PLpgSQL_if_elsif                  // one ELSIF arm of an IF statement
	T_PLpgSQL_stmt_loop                 // unconditional LOOP … END LOOP
	T_PLpgSQL_stmt_while                // WHILE cond LOOP … END LOOP
	T_PLpgSQL_stmt_exit                 // EXIT / CONTINUE [label] [WHEN cond]
	T_PLpgSQL_stmt_fori                 // integer FOR (FOR i IN a..b LOOP)
	T_PLpgSQL_stmt_fors                 // query FOR (FOR r IN query LOOP)
	T_PLpgSQL_stmt_foreach_a            // FOREACH x IN ARRAY expr LOOP
	T_PLpgSQL_stmt_case                 // CASE … WHEN … END CASE
	T_PLpgSQL_case_when                 // one WHEN arm of a CASE statement
	T_PLpgSQL_stmt_execsql              // an embedded SQL statement (SELECT/INSERT/…)
	T_PLpgSQL_stmt_perform              // PERFORM expr
	T_PLpgSQL_stmt_call                 // CALL / DO
	T_PLpgSQL_stmt_return               // RETURN [expr]
	T_PLpgSQL_stmt_return_next          // RETURN NEXT expr
	T_PLpgSQL_stmt_return_query         // RETURN QUERY query
	T_PLpgSQL_stmt_dynexecute           // EXECUTE expr [INTO …] [USING …]
	T_PLpgSQL_stmt_dynfors              // FOR var IN EXECUTE expr LOOP
	T_PLpgSQL_stmt_open                 // OPEN cursor …
	T_PLpgSQL_stmt_fetch                // FETCH / MOVE … cursor
	T_PLpgSQL_stmt_close                // CLOSE cursor
	T_PLpgSQL_alias                     // name ALIAS FOR target
	T_PLpgSQL_stmt_raise                // RAISE [level] […] [USING …]
	T_PLpgSQL_raise_option              // one USING option of a RAISE
	T_PLpgSQL_stmt_assert               // ASSERT cond [, message]
	T_PLpgSQL_exception                 // one EXCEPTION … WHEN clause
	T_PLpgSQL_condition                 // one condition of a WHEN clause
	T_PLpgSQL_stmt_getdiag              // GET [CURRENT|STACKED] DIAGNOSTICS …
	T_PLpgSQL_diag_item                 // one item of a GET DIAGNOSTICS list
	T_PLpgSQL_stmt_commit               // COMMIT [AND [NO] CHAIN]
	T_PLpgSQL_stmt_rollback             // ROLLBACK [AND [NO] CHAIN]
	T_PLpgSQL_cursor_arg                // one bound-cursor OPEN argument ([name :=] value)
)

func (NodeTag) String

func (nt NodeTag) String() string

String returns the string representation of a NodeTag.

type PLpgSQL_alias

type PLpgSQL_alias struct {
	BaseNode
	Dno     int    `json:"dno,omitempty"`
	Refname string `json:"refname,omitempty"` // the alias name
	Target  string `json:"target,omitempty"`  // the aliased (existing) name
}

PLpgSQL_alias represents an `name ALIAS FOR target` declaration. PG has no declaration node for this — ALIAS is a pure namespace side-effect (plpgsql_ns_additem) — so this is our parse-level carrier so the alias appears in the DECLARE-section datum list and round-trips. Target is the aliased name as written (PG resolves it to an existing variable).

func CloneRefOfPLpgSQL_alias

func CloneRefOfPLpgSQL_alias(n *PLpgSQL_alias) *PLpgSQL_alias

CloneRefOfPLpgSQL_alias creates a deep clone of the input.

func NewPLpgSQL_alias

func NewPLpgSQL_alias(refname string) *PLpgSQL_alias

func (*PLpgSQL_alias) DatumNo

func (a *PLpgSQL_alias) DatumNo() int

An ALIAS has no PG datum of its own (it is a namespace side effect that points at the aliased variable). Our parser keeps it in the DECLARE-section datum list so it round-trips and so an aliased name resolves like any other; it carries a real dno for that resolution.

func (*PLpgSQL_alias) SetDatumNo

func (a *PLpgSQL_alias) SetDatumNo(dno int)

func (*PLpgSQL_alias) SqlString

func (a *PLpgSQL_alias) SqlString() string

func (*PLpgSQL_alias) String

func (a *PLpgSQL_alias) String() string

type PLpgSQL_case_when

type PLpgSQL_case_when struct {
	BaseNode
	Expr  *PLpgSQL_expr `json:"expr,omitempty"`  // WHEN expression
	Stmts []Stmt        `json:"stmts,omitempty"` // statements run when Expr matches
}

PLpgSQL_case_when is one WHEN arm of a CASE statement (PG's PLpgSQL_case_when). Helper node (Node, not Stmt), like PLpgSQL_if_elsif; its deparse includes the leading `WHEN … THEN` so the enclosing CASE renders the arms by concatenation. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:632-637

func CloneRefOfPLpgSQL_case_when

func CloneRefOfPLpgSQL_case_when(n *PLpgSQL_case_when) *PLpgSQL_case_when

CloneRefOfPLpgSQL_case_when creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_case_when

func CloneSliceOfRefOfPLpgSQL_case_when(n []*PLpgSQL_case_when) []*PLpgSQL_case_when

CloneSliceOfRefOfPLpgSQL_case_when creates a deep clone of the input.

func NewPLpgSQL_case_when

func NewPLpgSQL_case_when() *PLpgSQL_case_when

func (*PLpgSQL_case_when) SqlString

func (w *PLpgSQL_case_when) SqlString() string

func (*PLpgSQL_case_when) String

func (w *PLpgSQL_case_when) String() string

type PLpgSQL_condition

type PLpgSQL_condition struct {
	BaseNode
	Condname string `json:"condname,omitempty"` // condition name, or the SQLSTATE code
}

PLpgSQL_condition is one condition of a WHEN clause (PG's PLpgSQL_condition): a named error condition, or a `SQLSTATE 'xxxxx'` code. PG's sqlerrstate (the resolved SQLSTATE int) is dropped — we don't resolve — and PG's `next` linked list is represented as a slice on PLpgSQL_exception.

The two forms are not stored with a flag: a SQLSTATE code and a condition name occupy disjoint string-spaces (the scanner lowercases identifiers, so a name always has lowercase letters, while a SQLSTATE code is five [0-9A-Z] characters), so IsSQLStateCode recovers the WHEN form from Condname alone. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:469-474

func CloneRefOfPLpgSQL_condition

func CloneRefOfPLpgSQL_condition(n *PLpgSQL_condition) *PLpgSQL_condition

CloneRefOfPLpgSQL_condition creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_condition

func CloneSliceOfRefOfPLpgSQL_condition(n []*PLpgSQL_condition) []*PLpgSQL_condition

CloneSliceOfRefOfPLpgSQL_condition creates a deep clone of the input.

func NewPLpgSQL_condition

func NewPLpgSQL_condition(condname string) *PLpgSQL_condition

func (*PLpgSQL_condition) SqlString

func (c *PLpgSQL_condition) SqlString() string

func (*PLpgSQL_condition) String

func (c *PLpgSQL_condition) String() string

type PLpgSQL_cursor_arg

type PLpgSQL_cursor_arg struct {
	BaseNode
	Name  string        `json:"name,omitempty"` // `name :=` label, or "" if positional
	Value *PLpgSQL_expr `json:"value"`          // the argument value expression
}

PLpgSQL_cursor_arg is one argument in a bound-cursor OPEN list: a value expression with an optional PL/pgSQL `name :=` label (`OPEN c(p := 20)`). Name is "" for a positional argument. PG has no matching node — it resolves the whole list into a single positional argquery (read_cursor_args) — but with no declared-parameter resolution we cannot reorder, so we keep each argument's surface form for a faithful, semantically-correct deparse.

func CloneRefOfPLpgSQL_cursor_arg

func CloneRefOfPLpgSQL_cursor_arg(n *PLpgSQL_cursor_arg) *PLpgSQL_cursor_arg

CloneRefOfPLpgSQL_cursor_arg creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_cursor_arg

func CloneSliceOfRefOfPLpgSQL_cursor_arg(n []*PLpgSQL_cursor_arg) []*PLpgSQL_cursor_arg

CloneSliceOfRefOfPLpgSQL_cursor_arg creates a deep clone of the input.

func NewPLpgSQL_cursor_arg

func NewPLpgSQL_cursor_arg(name string, value *PLpgSQL_expr) *PLpgSQL_cursor_arg

func (*PLpgSQL_cursor_arg) SqlString

func (a *PLpgSQL_cursor_arg) SqlString() string

func (*PLpgSQL_cursor_arg) String

func (a *PLpgSQL_cursor_arg) String() string

type PLpgSQL_diag_item

type PLpgSQL_diag_item struct {
	BaseNode
	Kind   PLpgSQL_getdiag_kind `json:"kind,omitempty"`   // the requested diagnostic
	Target string               `json:"target,omitempty"` // assignment target (name, as written)
}

PLpgSQL_diag_item is one `target := item` entry of a GET DIAGNOSTICS list (PG's PLpgSQL_diag_item). PG stores the resolved target variable (`dno`); we keep the target name as text. Node, not Stmt. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:572-576

func CloneRefOfPLpgSQL_diag_item

func CloneRefOfPLpgSQL_diag_item(n *PLpgSQL_diag_item) *PLpgSQL_diag_item

CloneRefOfPLpgSQL_diag_item creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_diag_item

func CloneSliceOfRefOfPLpgSQL_diag_item(n []*PLpgSQL_diag_item) []*PLpgSQL_diag_item

CloneSliceOfRefOfPLpgSQL_diag_item creates a deep clone of the input.

func NewPLpgSQL_diag_item

func NewPLpgSQL_diag_item(kind PLpgSQL_getdiag_kind, target string) *PLpgSQL_diag_item

func (*PLpgSQL_diag_item) SqlString

func (d *PLpgSQL_diag_item) SqlString() string

func (*PLpgSQL_diag_item) String

func (d *PLpgSQL_diag_item) String() string

type PLpgSQL_exception

type PLpgSQL_exception struct {
	BaseNode
	Conditions []*PLpgSQL_condition `json:"conditions,omitempty"` // OR-list of conditions
	Action     []Stmt               `json:"action,omitempty"`     // statements run by this handler
}

PLpgSQL_exception is one `WHEN condition [OR condition …] THEN …` handler clause (PG's PLpgSQL_exception). Helper node (Node, not Stmt), like PLpgSQL_case_when; its deparse includes the leading `WHEN … THEN` so the enclosing block renders the clauses by concatenation. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:489-494

func CloneRefOfPLpgSQL_exception

func CloneRefOfPLpgSQL_exception(n *PLpgSQL_exception) *PLpgSQL_exception

CloneRefOfPLpgSQL_exception creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_exception

func CloneSliceOfRefOfPLpgSQL_exception(n []*PLpgSQL_exception) []*PLpgSQL_exception

CloneSliceOfRefOfPLpgSQL_exception creates a deep clone of the input.

func NewPLpgSQL_exception

func NewPLpgSQL_exception() *PLpgSQL_exception

func (*PLpgSQL_exception) SqlString

func (e *PLpgSQL_exception) SqlString() string

func (*PLpgSQL_exception) String

func (e *PLpgSQL_exception) String() string

type PLpgSQL_exception_block

type PLpgSQL_exception_block struct {
	BaseNode
	ExcList []*PLpgSQL_exception `json:"exc_list,omitempty"` // WHEN clauses, in order
}

PLpgSQL_exception_block is the EXCEPTION section of a block (PG's PLpgSQL_exception_block): the list of WHEN handler clauses. PG's implicit sqlstate_varno / sqlerrm_varno (the namespace variables it injects) are dropped — we have no namespace. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:479-484

func CloneRefOfPLpgSQL_exception_block

func CloneRefOfPLpgSQL_exception_block(n *PLpgSQL_exception_block) *PLpgSQL_exception_block

CloneRefOfPLpgSQL_exception_block creates a deep clone of the input.

func NewPLpgSQL_exception_block

func NewPLpgSQL_exception_block() *PLpgSQL_exception_block

func (*PLpgSQL_exception_block) SqlString

func (e *PLpgSQL_exception_block) SqlString() string

func (*PLpgSQL_exception_block) String

func (e *PLpgSQL_exception_block) String() string

type PLpgSQL_expr

type PLpgSQL_expr struct {
	BaseNode
	// Query is the verbatim SQL text from the function body (PG's expr->query).
	Query string `json:"query,omitempty"`
	// ParseMode records how Query should be parsed, mirroring PG's
	// PLpgSQL_expr.parseMode. Set by read_sql_construct; defaults to
	// RAW_PARSE_DEFAULT (a full statement).
	ParseMode RawParseMode `json:"parse_mode,omitempty"`
	// Parsed is the SQL AST that Query parses to. PG has no parse-time
	// equivalent: it stores only the text and parses lazily at execution via
	// SPI (its `plan` field), validating syntax at compile time and discarding
	// the tree. We would parse eagerly instead, because the gateway analyzes the
	// body statically and never executes it — but this is currently left nil
	// (turning Query into an ast.Stmt is a separate planner-side step).
	Parsed ast.Stmt `json:"-"`
}

PLpgSQL_expr is an embedded SQL fragment inside a PL/pgSQL body — the source of an assignment, a query in PERFORM/RETURN, an IF/WHILE condition, a stmt_execsql, etc. It is the boundary between the two AST hierarchies and the node the Tier-1 walker exists to reach: Parsed is handed to the SQL-side analyzeStatement. PG keeps a compiled SPI plan here; for static analysis we keep the parsed SQL tree instead and drop all the execution/caching fields. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:218-267

func CloneRefOfPLpgSQL_expr

func CloneRefOfPLpgSQL_expr(n *PLpgSQL_expr) *PLpgSQL_expr

CloneRefOfPLpgSQL_expr creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_expr

func CloneSliceOfRefOfPLpgSQL_expr(n []*PLpgSQL_expr) []*PLpgSQL_expr

CloneSliceOfRefOfPLpgSQL_expr creates a deep clone of the input.

func NewPLpgSQL_expr

func NewPLpgSQL_expr(query string) *PLpgSQL_expr

func (*PLpgSQL_expr) SqlString

func (e *PLpgSQL_expr) SqlString() string

SqlString returns the verbatim fragment text.

func (*PLpgSQL_expr) String

func (e *PLpgSQL_expr) String() string

type PLpgSQL_function

type PLpgSQL_function struct {
	BaseNode
	Action *PLpgSQL_stmt_block `json:"action,omitempty"` // the function body block

	ResolveOption     PLpgSQL_resolve_option `json:"resolve_option,omitempty"`      // #variable_conflict
	PrintStrictParams string                 `json:"print_strict_params,omitempty"` // #print_strict_params on|off ("" = unset)
	DumpExecTree      bool                   `json:"dump_exec_tree,omitempty"`      // #option dump
}

PLpgSQL_function is the root of a parsed PL/pgSQL function body. As in PG, the body is a single top-level block (PG's function->action). The many execution-engine fields of PG's struct (datum array, statement ids, etc.) are intentionally omitted — this is a parse tree for static analysis.

The comp_options preamble fields (ResolveOption, PrintStrictParams, DumpExecTree) capture PG's #-directives so a body round-trips. They are semantically inert here: we neither resolve names nor execute, so the directives only affect deparse. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:966-1016

func CloneRefOfPLpgSQL_function

func CloneRefOfPLpgSQL_function(n *PLpgSQL_function) *PLpgSQL_function

CloneRefOfPLpgSQL_function creates a deep clone of the input.

func NewPLpgSQL_function

func NewPLpgSQL_function() *PLpgSQL_function

func (*PLpgSQL_function) SqlString

func (n *PLpgSQL_function) SqlString() string

func (*PLpgSQL_function) String

func (n *PLpgSQL_function) String() string

type PLpgSQL_getdiag_kind

type PLpgSQL_getdiag_kind int

PLpgSQL_getdiag_kind identifies which diagnostic value a GET DIAGNOSTICS item requests (PG's PLpgSQL_getdiag_kind). Values and order match PG exactly. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:147-162

const (
	PLPGSQL_GETDIAG_ROW_COUNT PLpgSQL_getdiag_kind = iota
	PLPGSQL_GETDIAG_ROUTINE_OID
	PLPGSQL_GETDIAG_CONTEXT
	PLPGSQL_GETDIAG_ERROR_CONTEXT
	PLPGSQL_GETDIAG_ERROR_DETAIL
	PLPGSQL_GETDIAG_ERROR_HINT
	PLPGSQL_GETDIAG_RETURNED_SQLSTATE
	PLPGSQL_GETDIAG_COLUMN_NAME
	PLPGSQL_GETDIAG_CONSTRAINT_NAME
	PLPGSQL_GETDIAG_DATATYPE_NAME
	PLPGSQL_GETDIAG_MESSAGE_TEXT
	PLPGSQL_GETDIAG_TABLE_NAME
	PLPGSQL_GETDIAG_SCHEMA_NAME
)

func (PLpgSQL_getdiag_kind) KindName

func (k PLpgSQL_getdiag_kind) KindName() string

KindName returns the keyword spelling of a diagnostic kind (PG's plpgsql_getdiag_kindname), used both for the deparse and in the STACKED/CURRENT validation error messages.

type PLpgSQL_if_elsif

type PLpgSQL_if_elsif struct {
	BaseNode
	Cond  *PLpgSQL_expr `json:"cond,omitempty"`  // boolean expression for this arm
	Stmts []Stmt        `json:"stmts,omitempty"` // statements run when Cond holds
}

PLpgSQL_if_elsif is one ELSIF arm of an IF statement (PG's PLpgSQL_if_elsif). PG keeps it as a plain helper struct, not a PLpgSQL_stmt, so this implements Node but not Stmt. Its deparse includes the leading `ELSIF … THEN` so the enclosing IF can render the arms by concatenation. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:607-612

func CloneRefOfPLpgSQL_if_elsif

func CloneRefOfPLpgSQL_if_elsif(n *PLpgSQL_if_elsif) *PLpgSQL_if_elsif

CloneRefOfPLpgSQL_if_elsif creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_if_elsif

func CloneSliceOfRefOfPLpgSQL_if_elsif(n []*PLpgSQL_if_elsif) []*PLpgSQL_if_elsif

CloneSliceOfRefOfPLpgSQL_if_elsif creates a deep clone of the input.

func NewPLpgSQL_if_elsif

func NewPLpgSQL_if_elsif() *PLpgSQL_if_elsif

func (*PLpgSQL_if_elsif) SqlString

func (e *PLpgSQL_if_elsif) SqlString() string

func (*PLpgSQL_if_elsif) String

func (e *PLpgSQL_if_elsif) String() string

type PLpgSQL_raise_option

type PLpgSQL_raise_option struct {
	BaseNode
	OptType RaiseOptionType `json:"opt_type,omitempty"` // which USING option
	Expr    *PLpgSQL_expr   `json:"expr,omitempty"`     // the option value
}

PLpgSQL_raise_option is one `option = expr` entry of a RAISE ... USING clause (PG's PLpgSQL_raise_option). Helper node (Node, not Stmt), like PLpgSQL_case_when. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:870-874

func CloneRefOfPLpgSQL_raise_option

func CloneRefOfPLpgSQL_raise_option(n *PLpgSQL_raise_option) *PLpgSQL_raise_option

CloneRefOfPLpgSQL_raise_option creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_raise_option

func CloneSliceOfRefOfPLpgSQL_raise_option(n []*PLpgSQL_raise_option) []*PLpgSQL_raise_option

CloneSliceOfRefOfPLpgSQL_raise_option creates a deep clone of the input.

func NewPLpgSQL_raise_option

func NewPLpgSQL_raise_option(optType RaiseOptionType) *PLpgSQL_raise_option

func (*PLpgSQL_raise_option) SqlString

func (o *PLpgSQL_raise_option) SqlString() string

func (*PLpgSQL_raise_option) String

func (o *PLpgSQL_raise_option) String() string

type PLpgSQL_rec

type PLpgSQL_rec struct {
	BaseNode
	Dno        int           `json:"dno,omitempty"`
	Refname    string        `json:"refname,omitempty"`
	IsConst    bool          `json:"is_const,omitempty"`
	NotNull    bool          `json:"not_null,omitempty"`
	DataType   *PLpgSQL_type `json:"datatype,omitempty"`    // the RECORD / x%ROWTYPE text, as written
	DefaultVal *PLpgSQL_expr `json:"default_val,omitempty"` // initializer expression, or nil
}

PLpgSQL_rec is a record variable — the RECORD pseudo-type or a `%ROWTYPE` declaration, the composite cases we can recognize syntactically without a catalog. A named composite type still can't be told from a scalar, so it stays a PLpgSQL_var. PG's runtime linkage (rectypeid, firstfield, erh) is dropped; the parse-level fields mirror PLpgSQL_var so a record declaration deparses identically to how it was written. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:389-415

func CloneRefOfPLpgSQL_rec

func CloneRefOfPLpgSQL_rec(n *PLpgSQL_rec) *PLpgSQL_rec

CloneRefOfPLpgSQL_rec creates a deep clone of the input.

func NewPLpgSQL_rec

func NewPLpgSQL_rec(refname string) *PLpgSQL_rec

func (*PLpgSQL_rec) DatumNo

func (r *PLpgSQL_rec) DatumNo() int

func (*PLpgSQL_rec) SetDatumNo

func (r *PLpgSQL_rec) SetDatumNo(dno int)

func (*PLpgSQL_rec) SqlString

func (r *PLpgSQL_rec) SqlString() string

SqlString deparses a record declaration. It intentionally mirrors PLpgSQL_var's scalar path (a record has no COLLATE or cursor fields), so a declaration reclassified from var to rec round-trips byte-for-byte.

func (*PLpgSQL_rec) String

func (r *PLpgSQL_rec) String() string

type PLpgSQL_recfield

type PLpgSQL_recfield struct {
	BaseNode
	Dno         int    `json:"dno,omitempty"`
	FieldName   string `json:"field_name,omitempty"`
	RecParentNo int    `json:"rec_parent_no,omitempty"` // dno of the parent record
}

PLpgSQL_recfield is a reference to one field of a record variable (rec.field), built lazily by the scanner the first time the reference is seen. RecParentNo is the dno of the parent record. PG's runtime type-cache fields are dropped. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:420-432

func CloneRefOfPLpgSQL_recfield

func CloneRefOfPLpgSQL_recfield(n *PLpgSQL_recfield) *PLpgSQL_recfield

CloneRefOfPLpgSQL_recfield creates a deep clone of the input.

func NewPLpgSQL_recfield

func NewPLpgSQL_recfield(fieldName string) *PLpgSQL_recfield

func (*PLpgSQL_recfield) DatumNo

func (r *PLpgSQL_recfield) DatumNo() int

func (*PLpgSQL_recfield) SetDatumNo

func (r *PLpgSQL_recfield) SetDatumNo(dno int)

func (*PLpgSQL_recfield) SqlString

func (r *PLpgSQL_recfield) SqlString() string

SqlString renders the field name. A recfield never appears in a declaration; a resolved rec.field target deparses from the statement's captured name text.

func (*PLpgSQL_recfield) String

func (r *PLpgSQL_recfield) String() string

type PLpgSQL_resolve_option

type PLpgSQL_resolve_option int8

PLpgSQL_resolve_option mirrors PG's #variable_conflict setting (plpgsql.h:183-188). PLPGSQL_RESOLVE_UNSPECIFIED is our own addition (not in PG): it marks the absence of a #variable_conflict directive so deparse omits it, where PG instead defaults the field from the plpgsql.variable_conflict GUC. The remaining values match PG's enum meanings.

const (
	PLPGSQL_RESOLVE_UNSPECIFIED PLpgSQL_resolve_option = iota
	PLPGSQL_RESOLVE_ERROR                              // #variable_conflict error
	PLPGSQL_RESOLVE_VARIABLE                           // #variable_conflict use_variable
	PLPGSQL_RESOLVE_COLUMN                             // #variable_conflict use_column
)

type PLpgSQL_row

type PLpgSQL_row struct {
	BaseNode
	Dno        int      `json:"dno,omitempty"`
	Refname    string   `json:"refname,omitempty"`
	Fieldnames []string `json:"fieldnames,omitempty"`
	Varnos     []int    `json:"varnos,omitempty"`
}

PLpgSQL_row represents one or more scalar variables listed together — a comma-separated FOR/FOREACH targetlist or an INTO list. It cannot be named from source, so Refname is conventionally "(unnamed row)". Members are recorded by name and by dno: Varnos is 1:1 with Fieldnames, and Varnos[i] is the dno of Fieldnames[i] — or -1 when that member did not resolve to a datum (a compound name we cannot resolve without a catalog). It is a transient resolution artifact used for assignability checks; statement nodes still store the target as text for deparse, so PLpgSQL_row never appears in a decls list. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:363-384

func CloneRefOfPLpgSQL_row

func CloneRefOfPLpgSQL_row(n *PLpgSQL_row) *PLpgSQL_row

CloneRefOfPLpgSQL_row creates a deep clone of the input.

func NewPLpgSQL_row

func NewPLpgSQL_row(refname string) *PLpgSQL_row

func (*PLpgSQL_row) DatumNo

func (r *PLpgSQL_row) DatumNo() int

func (*PLpgSQL_row) SetDatumNo

func (r *PLpgSQL_row) SetDatumNo(dno int)

func (*PLpgSQL_row) SqlString

func (r *PLpgSQL_row) SqlString() string

func (*PLpgSQL_row) String

func (r *PLpgSQL_row) String() string

type PLpgSQL_stmt_assert

type PLpgSQL_stmt_assert struct {
	BaseNode
	Cond    *PLpgSQL_expr `json:"cond,omitempty"`    // the asserted condition
	Message *PLpgSQL_expr `json:"message,omitempty"` // optional message expression, or nil
}

PLpgSQL_stmt_assert is an ASSERT statement (PG's PLpgSQL_stmt_assert): `ASSERT cond [, message]` — raise assert_failure if cond is not true. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:879-886

func CloneRefOfPLpgSQL_stmt_assert

func CloneRefOfPLpgSQL_stmt_assert(n *PLpgSQL_stmt_assert) *PLpgSQL_stmt_assert

CloneRefOfPLpgSQL_stmt_assert creates a deep clone of the input.

func NewPLpgSQL_stmt_assert

func NewPLpgSQL_stmt_assert() *PLpgSQL_stmt_assert

func (*PLpgSQL_stmt_assert) SqlString

func (s *PLpgSQL_stmt_assert) SqlString() string

func (*PLpgSQL_stmt_assert) String

func (s *PLpgSQL_stmt_assert) String() string

type PLpgSQL_stmt_assign

type PLpgSQL_stmt_assign struct {
	BaseNode
	Target string        `json:"target,omitempty"` // assignment target (variable name, as written)
	Expr   *PLpgSQL_expr `json:"expr,omitempty"`   // right-hand side expression
}

PLpgSQL_stmt_assign is an assignment statement (`target := expr`). PG stores the resolved variable (varno) and the whole `target := value` as one ASSIGN-mode expr; for the parse-level port (no variable resolution) we keep the target as written and the right-hand side as its own expression. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:514-521

func CloneRefOfPLpgSQL_stmt_assign

func CloneRefOfPLpgSQL_stmt_assign(n *PLpgSQL_stmt_assign) *PLpgSQL_stmt_assign

CloneRefOfPLpgSQL_stmt_assign creates a deep clone of the input.

func NewPLpgSQL_stmt_assign

func NewPLpgSQL_stmt_assign(target string) *PLpgSQL_stmt_assign

func (*PLpgSQL_stmt_assign) SqlString

func (a *PLpgSQL_stmt_assign) SqlString() string

func (*PLpgSQL_stmt_assign) String

func (a *PLpgSQL_stmt_assign) String() string

type PLpgSQL_stmt_block

type PLpgSQL_stmt_block struct {
	BaseNode
	Label      string                   `json:"label,omitempty"`      // optional block label
	Decls      []Datum                  `json:"decls,omitempty"`      // DECLARE-section variables
	Body       []Stmt                   `json:"body,omitempty"`       // statements between BEGIN and END
	Exceptions *PLpgSQL_exception_block `json:"exceptions,omitempty"` // EXCEPTION section, or nil
}

PLpgSQL_stmt_block is a BEGIN … END block. PG's execution bookkeeping (stmtid, n_initvars, initvarnos) is dropped; cmd_type and lineno are carried by BaseNode. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:499-509

func CloneRefOfPLpgSQL_stmt_block

func CloneRefOfPLpgSQL_stmt_block(n *PLpgSQL_stmt_block) *PLpgSQL_stmt_block

CloneRefOfPLpgSQL_stmt_block creates a deep clone of the input.

func NewPLpgSQL_stmt_block

func NewPLpgSQL_stmt_block() *PLpgSQL_stmt_block

func (*PLpgSQL_stmt_block) SqlString

func (b *PLpgSQL_stmt_block) SqlString() string

SqlString deparses the block: the optional label, the DECLARE section, BEGIN, the body, the optional EXCEPTION section, and END with its echoed label.

func (*PLpgSQL_stmt_block) String

func (b *PLpgSQL_stmt_block) String() string

type PLpgSQL_stmt_call

type PLpgSQL_stmt_call struct {
	BaseNode
	Expr   *PLpgSQL_expr `json:"expr,omitempty"`    // the CALL/DO statement text
	IsCall bool          `json:"is_call,omitempty"` // true for CALL, false for DO
}

PLpgSQL_stmt_call is `CALL proc(...)` or `DO $$…$$` (PG's PLpgSQL_stmt_call; PG uses one struct for both). Expr is the whole statement text, including the CALL/DO keyword. IsCall distinguishes the two. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:537-545

func CloneRefOfPLpgSQL_stmt_call

func CloneRefOfPLpgSQL_stmt_call(n *PLpgSQL_stmt_call) *PLpgSQL_stmt_call

CloneRefOfPLpgSQL_stmt_call creates a deep clone of the input.

func NewPLpgSQL_stmt_call

func NewPLpgSQL_stmt_call(isCall bool) *PLpgSQL_stmt_call

func (*PLpgSQL_stmt_call) SqlString

func (s *PLpgSQL_stmt_call) SqlString() string

func (*PLpgSQL_stmt_call) String

func (s *PLpgSQL_stmt_call) String() string

type PLpgSQL_stmt_case

type PLpgSQL_stmt_case struct {
	BaseNode
	TestExpr  *PLpgSQL_expr        `json:"test_expr,omitempty"`  // simple-CASE test expression, or nil
	WhenList  []*PLpgSQL_case_when `json:"when_list,omitempty"`  // WHEN arms, in order
	HaveElse  bool                 `json:"have_else,omitempty"`  // an ELSE clause is present (possibly empty)
	ElseStmts []Stmt               `json:"else_stmts,omitempty"` // ELSE branch statements
}

PLpgSQL_stmt_case is a CASE statement (PG's PLpgSQL_stmt_case): either simple (`CASE expr WHEN val THEN …`) or searched (`CASE WHEN cond THEN …`), with an optional ELSE. TestExpr is nil for the searched form. Drops PG's resolved `t_varno`. HaveElse records whether an ELSE was written, even if its body is empty — PG keeps this (its `have_else`) because a present ELSE suppresses the runtime CASE_NOT_FOUND error, unlike IF. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:617-627

func CloneRefOfPLpgSQL_stmt_case

func CloneRefOfPLpgSQL_stmt_case(n *PLpgSQL_stmt_case) *PLpgSQL_stmt_case

CloneRefOfPLpgSQL_stmt_case creates a deep clone of the input.

func NewPLpgSQL_stmt_case

func NewPLpgSQL_stmt_case() *PLpgSQL_stmt_case

func (*PLpgSQL_stmt_case) SqlString

func (s *PLpgSQL_stmt_case) SqlString() string

func (*PLpgSQL_stmt_case) String

func (s *PLpgSQL_stmt_case) String() string

type PLpgSQL_stmt_close

type PLpgSQL_stmt_close struct {
	BaseNode
	Curvar string `json:"curvar,omitempty"` // cursor name, as written
}

PLpgSQL_stmt_close is `CLOSE cursor` (PG's PLpgSQL_stmt_close). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:794-800

func CloneRefOfPLpgSQL_stmt_close

func CloneRefOfPLpgSQL_stmt_close(n *PLpgSQL_stmt_close) *PLpgSQL_stmt_close

CloneRefOfPLpgSQL_stmt_close creates a deep clone of the input.

func NewPLpgSQL_stmt_close

func NewPLpgSQL_stmt_close() *PLpgSQL_stmt_close

func (*PLpgSQL_stmt_close) SqlString

func (s *PLpgSQL_stmt_close) SqlString() string

func (*PLpgSQL_stmt_close) String

func (s *PLpgSQL_stmt_close) String() string

type PLpgSQL_stmt_commit

type PLpgSQL_stmt_commit struct {
	BaseNode
	Chain bool `json:"chain,omitempty"` // AND CHAIN
}

PLpgSQL_stmt_commit is `COMMIT [AND [NO] CHAIN]` (PG's PLpgSQL_stmt_commit): commit the current transaction inside a procedure. Chain records AND CHAIN. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:550-556

func CloneRefOfPLpgSQL_stmt_commit

func CloneRefOfPLpgSQL_stmt_commit(n *PLpgSQL_stmt_commit) *PLpgSQL_stmt_commit

CloneRefOfPLpgSQL_stmt_commit creates a deep clone of the input.

func NewPLpgSQL_stmt_commit

func NewPLpgSQL_stmt_commit() *PLpgSQL_stmt_commit

func (*PLpgSQL_stmt_commit) SqlString

func (s *PLpgSQL_stmt_commit) SqlString() string

func (*PLpgSQL_stmt_commit) String

func (s *PLpgSQL_stmt_commit) String() string

type PLpgSQL_stmt_dynexecute

type PLpgSQL_stmt_dynexecute struct {
	BaseNode
	Query      *PLpgSQL_expr   `json:"query,omitempty"`       // the SQL-string expression
	Into       bool            `json:"into,omitempty"`        // an INTO clause is present
	Strict     bool            `json:"strict,omitempty"`      // INTO STRICT
	Target     string          `json:"target,omitempty"`      // INTO target text (names)
	Params     []*PLpgSQL_expr `json:"params,omitempty"`      // USING expressions
	UsingFirst bool            `json:"using_first,omitempty"` // USING appeared before INTO
}

PLpgSQL_stmt_dynexecute is `EXECUTE query [INTO [STRICT] target] [USING …]` (PG's PLpgSQL_stmt_dynexecute): run a dynamically-built SQL string. This is the primary node the Tier-1 dynamic-EXECUTE policy reasons about. PG resolves the INTO target to variables; we keep it as text. UsingFirst records the source order of the INTO and USING clauses (PG accepts them in either order) so the deparse round-trips. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:907-917

func CloneRefOfPLpgSQL_stmt_dynexecute

func CloneRefOfPLpgSQL_stmt_dynexecute(n *PLpgSQL_stmt_dynexecute) *PLpgSQL_stmt_dynexecute

CloneRefOfPLpgSQL_stmt_dynexecute creates a deep clone of the input.

func NewPLpgSQL_stmt_dynexecute

func NewPLpgSQL_stmt_dynexecute() *PLpgSQL_stmt_dynexecute

func (*PLpgSQL_stmt_dynexecute) SqlString

func (s *PLpgSQL_stmt_dynexecute) SqlString() string

func (*PLpgSQL_stmt_dynexecute) String

func (s *PLpgSQL_stmt_dynexecute) String() string

type PLpgSQL_stmt_dynfors

type PLpgSQL_stmt_dynfors struct {
	BaseNode
	Label  string          `json:"label,omitempty"`  // optional loop label
	Var    string          `json:"var,omitempty"`    // loop target name, as written
	Query  *PLpgSQL_expr   `json:"query,omitempty"`  // the SQL-string expression
	Params []*PLpgSQL_expr `json:"params,omitempty"` // USING expressions
	Body   []Stmt          `json:"body,omitempty"`   // loop body
}

PLpgSQL_stmt_dynfors is `FOR var IN EXECUTE query [USING …] LOOP … END LOOP` (PG's PLpgSQL_stmt_dynfors): iterate over the rows of a dynamically-built query. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:730-741

func CloneRefOfPLpgSQL_stmt_dynfors

func CloneRefOfPLpgSQL_stmt_dynfors(n *PLpgSQL_stmt_dynfors) *PLpgSQL_stmt_dynfors

CloneRefOfPLpgSQL_stmt_dynfors creates a deep clone of the input.

func NewPLpgSQL_stmt_dynfors

func NewPLpgSQL_stmt_dynfors() *PLpgSQL_stmt_dynfors

func (*PLpgSQL_stmt_dynfors) SqlString

func (s *PLpgSQL_stmt_dynfors) SqlString() string

func (*PLpgSQL_stmt_dynfors) String

func (s *PLpgSQL_stmt_dynfors) String() string

type PLpgSQL_stmt_execsql

type PLpgSQL_stmt_execsql struct {
	BaseNode
	Sqlstmt *PLpgSQL_expr `json:"sqlstmt,omitempty"` // the statement text, with any INTO clause removed
	Into    bool          `json:"into,omitempty"`    // an INTO clause is present
	Strict  bool          `json:"strict,omitempty"`  // INTO STRICT
	Target  string        `json:"target,omitempty"`  // INTO target text (names), or ""
}

PLpgSQL_stmt_execsql is an embedded SQL statement — any statement not handled by a dedicated PL/pgSQL production (SELECT, INSERT, UPDATE, DELETE, a bare function call, …), captured verbatim. PG's INTO-target extraction and mod_stmt flag are dropped (both need resolution / aren't needed for a parse-only port). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:891-902

func CloneRefOfPLpgSQL_stmt_execsql

func CloneRefOfPLpgSQL_stmt_execsql(n *PLpgSQL_stmt_execsql) *PLpgSQL_stmt_execsql

CloneRefOfPLpgSQL_stmt_execsql creates a deep clone of the input.

func NewPLpgSQL_stmt_execsql

func NewPLpgSQL_stmt_execsql() *PLpgSQL_stmt_execsql

func (*PLpgSQL_stmt_execsql) SqlString

func (s *PLpgSQL_stmt_execsql) SqlString() string

SqlString re-emits the statement, appending the INTO clause after the query. PG's make_execsql_stmt lifts the INTO clause out from wherever it appears (PL/pgSQL allows it almost anywhere); we re-emit it trailing, which PL/pgSQL also accepts — so the deparse round-trips to a stable fixpoint even though it is not byte-identical to a source that wrote INTO mid-statement.

func (*PLpgSQL_stmt_execsql) String

func (s *PLpgSQL_stmt_execsql) String() string

type PLpgSQL_stmt_exit

type PLpgSQL_stmt_exit struct {
	BaseNode
	IsExit bool          `json:"is_exit,omitempty"` // true for EXIT, false for CONTINUE
	Label  string        `json:"label,omitempty"`   // optional target label
	Cond   *PLpgSQL_expr `json:"cond,omitempty"`    // optional WHEN condition
}

PLpgSQL_stmt_exit is an EXIT or CONTINUE (PG's PLpgSQL_stmt_exit). IsExit distinguishes the two. Label and Cond (the optional WHEN expression) are both optional. PG's namespace-based validation (label exists, CONTINUE forbids block labels, EXIT/CONTINUE must be inside a loop) is dropped: we have no namespace, so we capture the statement without checking it. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:805-813

func CloneRefOfPLpgSQL_stmt_exit

func CloneRefOfPLpgSQL_stmt_exit(n *PLpgSQL_stmt_exit) *PLpgSQL_stmt_exit

CloneRefOfPLpgSQL_stmt_exit creates a deep clone of the input.

func NewPLpgSQL_stmt_exit

func NewPLpgSQL_stmt_exit(isExit bool) *PLpgSQL_stmt_exit

func (*PLpgSQL_stmt_exit) SqlString

func (s *PLpgSQL_stmt_exit) SqlString() string

func (*PLpgSQL_stmt_exit) String

func (s *PLpgSQL_stmt_exit) String() string

type PLpgSQL_stmt_fetch

type PLpgSQL_stmt_fetch struct {
	BaseNode
	Curvar              string         `json:"curvar,omitempty"`    // cursor name, as written
	Direction           FetchDirection `json:"direction,omitempty"` // fetch direction
	HowMany             int64          `json:"how_many,omitempty"`  // count when Expr is nil
	Expr                *PLpgSQL_expr  `json:"expr,omitempty"`      // count expression, or nil
	IsMove              bool           `json:"is_move,omitempty"`   // MOVE rather than FETCH
	Target              string         `json:"target,omitempty"`    // INTO target text (FETCH only)
	ReturnsMultipleRows bool           `json:"returns_multiple_rows,omitempty"`
}

PLpgSQL_stmt_fetch is `FETCH … cursor INTO target` or `MOVE … cursor` (PG's PLpgSQL_stmt_fetch; MOVE reuses the struct with IsMove). The direction is parsed to PG's (Direction, HowMany, Expr) model; the deparse renders a canonical direction clause, so equivalent surface forms (e.g. NEXT vs the default) round-trip to the same text. curvar/target are text (no resolution). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:777-789

func CloneRefOfPLpgSQL_stmt_fetch

func CloneRefOfPLpgSQL_stmt_fetch(n *PLpgSQL_stmt_fetch) *PLpgSQL_stmt_fetch

CloneRefOfPLpgSQL_stmt_fetch creates a deep clone of the input.

func NewPLpgSQL_stmt_fetch

func NewPLpgSQL_stmt_fetch(isMove bool) *PLpgSQL_stmt_fetch

func (*PLpgSQL_stmt_fetch) SqlString

func (s *PLpgSQL_stmt_fetch) SqlString() string

func (*PLpgSQL_stmt_fetch) String

func (s *PLpgSQL_stmt_fetch) String() string

type PLpgSQL_stmt_foreach_a

type PLpgSQL_stmt_foreach_a struct {
	BaseNode
	Label string        `json:"label,omitempty"` // optional loop label
	Var   string        `json:"var,omitempty"`   // loop variable name, as written
	Slice int           `json:"slice,omitempty"` // SLICE dimension, or 0 for none
	Expr  *PLpgSQL_expr `json:"expr,omitempty"`  // the array expression
	Body  []Stmt        `json:"body,omitempty"`  // loop body
}

PLpgSQL_stmt_foreach_a is a FOREACH-over-array loop (PG's PLpgSQL_stmt_foreach_a): `FOREACH var [SLICE n] IN ARRAY expr LOOP … END LOOP`. Drops PG's resolved `varno` — we keep the target name as written. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:746-756

func CloneRefOfPLpgSQL_stmt_foreach_a

func CloneRefOfPLpgSQL_stmt_foreach_a(n *PLpgSQL_stmt_foreach_a) *PLpgSQL_stmt_foreach_a

CloneRefOfPLpgSQL_stmt_foreach_a creates a deep clone of the input.

func NewPLpgSQL_stmt_foreach_a

func NewPLpgSQL_stmt_foreach_a() *PLpgSQL_stmt_foreach_a

func (*PLpgSQL_stmt_foreach_a) SqlString

func (s *PLpgSQL_stmt_foreach_a) SqlString() string

func (*PLpgSQL_stmt_foreach_a) String

func (s *PLpgSQL_stmt_foreach_a) String() string

type PLpgSQL_stmt_fori

type PLpgSQL_stmt_fori struct {
	BaseNode
	Label   string        `json:"label,omitempty"`   // optional loop label
	Var     string        `json:"var,omitempty"`     // loop variable name, as written
	Lower   *PLpgSQL_expr `json:"lower,omitempty"`   // lower bound
	Upper   *PLpgSQL_expr `json:"upper,omitempty"`   // upper bound
	Step    *PLpgSQL_expr `json:"step,omitempty"`    // BY step, or nil for the default (1)
	Reverse bool          `json:"reverse,omitempty"` // counts down when true
	Body    []Stmt        `json:"body,omitempty"`    // loop body
}

PLpgSQL_stmt_fori is an integer FOR loop (PG's PLpgSQL_stmt_fori): `FOR var IN [REVERSE] lower .. upper [BY step] LOOP … END LOOP`. The bounds are captured as expressions. Drops PG's resolved loop `var` datum — we keep the target name as written. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:667-679

func CloneRefOfPLpgSQL_stmt_fori

func CloneRefOfPLpgSQL_stmt_fori(n *PLpgSQL_stmt_fori) *PLpgSQL_stmt_fori

CloneRefOfPLpgSQL_stmt_fori creates a deep clone of the input.

func NewPLpgSQL_stmt_fori

func NewPLpgSQL_stmt_fori() *PLpgSQL_stmt_fori

func (*PLpgSQL_stmt_fori) SqlString

func (s *PLpgSQL_stmt_fori) SqlString() string

func (*PLpgSQL_stmt_fori) String

func (s *PLpgSQL_stmt_fori) String() string

type PLpgSQL_stmt_fors

type PLpgSQL_stmt_fors struct {
	BaseNode
	Label string        `json:"label,omitempty"` // optional loop label
	Var   string        `json:"var,omitempty"`   // loop target name, as written
	Query *PLpgSQL_expr `json:"query,omitempty"` // the query iterated over
	Body  []Stmt        `json:"body,omitempty"`  // loop body
}

PLpgSQL_stmt_fors is a query FOR loop (PG's PLpgSQL_stmt_fors): `FOR var IN query LOOP … END LOOP`. Without variable resolution we cannot distinguish a bound-cursor FOR loop from a query FOR loop, so cursor FOR loops are also represented here, with the cursor name captured as the query text. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:699-709

func CloneRefOfPLpgSQL_stmt_fors

func CloneRefOfPLpgSQL_stmt_fors(n *PLpgSQL_stmt_fors) *PLpgSQL_stmt_fors

CloneRefOfPLpgSQL_stmt_fors creates a deep clone of the input.

func NewPLpgSQL_stmt_fors

func NewPLpgSQL_stmt_fors() *PLpgSQL_stmt_fors

func (*PLpgSQL_stmt_fors) SqlString

func (s *PLpgSQL_stmt_fors) SqlString() string

func (*PLpgSQL_stmt_fors) String

func (s *PLpgSQL_stmt_fors) String() string

type PLpgSQL_stmt_getdiag

type PLpgSQL_stmt_getdiag struct {
	BaseNode
	IsStacked bool                 `json:"is_stacked,omitempty"` // STACKED vs CURRENT area
	DiagItems []*PLpgSQL_diag_item `json:"diag_items,omitempty"` // the requested items
}

PLpgSQL_stmt_getdiag is `GET [CURRENT|STACKED] DIAGNOSTICS target := item, …` (PG's PLpgSQL_stmt_getdiag): read diagnostic values into variables. IsStacked selects the STACKED (in-handler) vs CURRENT diagnostics area. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:581-588

func CloneRefOfPLpgSQL_stmt_getdiag

func CloneRefOfPLpgSQL_stmt_getdiag(n *PLpgSQL_stmt_getdiag) *PLpgSQL_stmt_getdiag

CloneRefOfPLpgSQL_stmt_getdiag creates a deep clone of the input.

func NewPLpgSQL_stmt_getdiag

func NewPLpgSQL_stmt_getdiag() *PLpgSQL_stmt_getdiag

func (*PLpgSQL_stmt_getdiag) SqlString

func (s *PLpgSQL_stmt_getdiag) SqlString() string

func (*PLpgSQL_stmt_getdiag) String

func (s *PLpgSQL_stmt_getdiag) String() string

type PLpgSQL_stmt_if

type PLpgSQL_stmt_if struct {
	BaseNode
	Cond      *PLpgSQL_expr       `json:"cond,omitempty"`       // boolean expression for THEN
	ThenBody  []Stmt              `json:"then_body,omitempty"`  // statements in the THEN branch
	ElsifList []*PLpgSQL_if_elsif `json:"elsif_list,omitempty"` // ELSIF arms, in order
	ElseBody  []Stmt              `json:"else_body,omitempty"`  // statements in the ELSE branch, or nil
}

PLpgSQL_stmt_if is an IF statement (PG's PLpgSQL_stmt_if, plpgsql.h): `IF cond THEN … [ELSIF cond THEN …] [ELSE …] END IF`. The ELSIF arms are PLpgSQL_if_elsif helper nodes; ElseBody is nil when there is no ELSE. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:593-602

func CloneRefOfPLpgSQL_stmt_if

func CloneRefOfPLpgSQL_stmt_if(n *PLpgSQL_stmt_if) *PLpgSQL_stmt_if

CloneRefOfPLpgSQL_stmt_if creates a deep clone of the input.

func NewPLpgSQL_stmt_if

func NewPLpgSQL_stmt_if() *PLpgSQL_stmt_if

func (*PLpgSQL_stmt_if) SqlString

func (s *PLpgSQL_stmt_if) SqlString() string

func (*PLpgSQL_stmt_if) String

func (s *PLpgSQL_stmt_if) String() string

type PLpgSQL_stmt_loop

type PLpgSQL_stmt_loop struct {
	BaseNode
	Label string `json:"label,omitempty"` // optional loop label
	Body  []Stmt `json:"body,omitempty"`  // statements between LOOP and END LOOP
}

PLpgSQL_stmt_loop is an unconditional `LOOP … END LOOP` (PG's PLpgSQL_stmt_loop). Label is the optional block label; it is echoed after END LOOP on deparse so the result re-parses (checkLabels requires a match). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:642-649

func CloneRefOfPLpgSQL_stmt_loop

func CloneRefOfPLpgSQL_stmt_loop(n *PLpgSQL_stmt_loop) *PLpgSQL_stmt_loop

CloneRefOfPLpgSQL_stmt_loop creates a deep clone of the input.

func NewPLpgSQL_stmt_loop

func NewPLpgSQL_stmt_loop() *PLpgSQL_stmt_loop

func (*PLpgSQL_stmt_loop) SqlString

func (s *PLpgSQL_stmt_loop) SqlString() string

func (*PLpgSQL_stmt_loop) String

func (s *PLpgSQL_stmt_loop) String() string

type PLpgSQL_stmt_open

type PLpgSQL_stmt_open struct {
	BaseNode
	Curvar        string                `json:"curvar,omitempty"`         // cursor name, as written
	CursorOptions int                   `json:"cursor_options,omitempty"` // SCROLL / NO SCROLL flags
	Args          []*PLpgSQL_cursor_arg `json:"args,omitempty"`           // bound-cursor args, `(…)`
	Query         *PLpgSQL_expr         `json:"query,omitempty"`          // FOR query
	DynQuery      *PLpgSQL_expr         `json:"dynquery,omitempty"`       // FOR EXECUTE expr
	Params        []*PLpgSQL_expr       `json:"params,omitempty"`         // USING expressions (dynamic)
}

PLpgSQL_stmt_open is `OPEN cursor …` (PG's PLpgSQL_stmt_open): open a bound cursor (optionally with args) or an unbound one with a `FOR query` / `FOR EXECUTE expr [USING …]`. curvar is the cursor name as text (no resolution). Exactly one of Args / Query / DynQuery is set.

PG stores the bound-cursor argument list as a single reordered positional `argquery` SELECT, built by resolving each value against the cursor's declared parameter row (read_cursor_args). We keep no such resolution, so we cannot reorder to positional; instead we retain each argument's surface form — its optional `name :=` label and value expression — as a PLpgSQL_cursor_arg. That keeps the deparse faithful (the labels are not lost) and, since we can't reorder, keeps named binding correct. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:761-772

func CloneRefOfPLpgSQL_stmt_open

func CloneRefOfPLpgSQL_stmt_open(n *PLpgSQL_stmt_open) *PLpgSQL_stmt_open

CloneRefOfPLpgSQL_stmt_open creates a deep clone of the input.

func NewPLpgSQL_stmt_open

func NewPLpgSQL_stmt_open() *PLpgSQL_stmt_open

func (*PLpgSQL_stmt_open) SqlString

func (s *PLpgSQL_stmt_open) SqlString() string

func (*PLpgSQL_stmt_open) String

func (s *PLpgSQL_stmt_open) String() string

type PLpgSQL_stmt_perform

type PLpgSQL_stmt_perform struct {
	BaseNode
	Expr *PLpgSQL_expr `json:"expr,omitempty"` // the expression to evaluate
}

PLpgSQL_stmt_perform is `PERFORM expr` (PG's PLpgSQL_stmt_perform): run a query and discard its result. Expr is the expression after PERFORM; PG rewrites the leading keyword to SELECT for execution, which is deferred (we keep the expression and re-emit PERFORM on deparse). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:526-532

func CloneRefOfPLpgSQL_stmt_perform

func CloneRefOfPLpgSQL_stmt_perform(n *PLpgSQL_stmt_perform) *PLpgSQL_stmt_perform

CloneRefOfPLpgSQL_stmt_perform creates a deep clone of the input.

func NewPLpgSQL_stmt_perform

func NewPLpgSQL_stmt_perform() *PLpgSQL_stmt_perform

func (*PLpgSQL_stmt_perform) SqlString

func (s *PLpgSQL_stmt_perform) SqlString() string

func (*PLpgSQL_stmt_perform) String

func (s *PLpgSQL_stmt_perform) String() string

type PLpgSQL_stmt_raise

type PLpgSQL_stmt_raise struct {
	BaseNode
	ElogLevel  RaiseLevel              `json:"elog_level,omitempty"`  // severity
	Condname   string                  `json:"condname,omitempty"`    // condition name / SQLSTATE, or ""
	IsSqlState bool                    `json:"is_sqlstate,omitempty"` // Condname is a SQLSTATE code
	HasMessage bool                    `json:"has_message,omitempty"` // an old-style message literal is present
	Message    string                  `json:"message,omitempty"`     // the message literal value (dequoted)
	Params     []*PLpgSQL_expr         `json:"params,omitempty"`      // expressions for the message
	Options    []*PLpgSQL_raise_option `json:"options,omitempty"`     // USING options
}

PLpgSQL_stmt_raise is a RAISE statement (PG's PLpgSQL_stmt_raise): report a message at a severity level, optionally with a condition name / SQLSTATE, an old-style format string with parameters, and a USING option list. A bare RAISE (all fields empty/default) re-throws the current error.

Condname holds either a condition name or, when IsSqlState is set, a 5-char SQLSTATE code — PG stores both in one char* and never deparses; IsSqlState records which so the deparse re-emits the right form. Message is the dequoted literal value (as PG keeps it); the deparse re-quotes it. HasMessage distinguishes an empty-string message literal (`RAISE ”`) from no message at all (a bare `RAISE` re-throw) — PG's `message == NULL` vs `""`. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:855-865

func CloneRefOfPLpgSQL_stmt_raise

func CloneRefOfPLpgSQL_stmt_raise(n *PLpgSQL_stmt_raise) *PLpgSQL_stmt_raise

CloneRefOfPLpgSQL_stmt_raise creates a deep clone of the input.

func NewPLpgSQL_stmt_raise

func NewPLpgSQL_stmt_raise() *PLpgSQL_stmt_raise

func (*PLpgSQL_stmt_raise) SqlString

func (s *PLpgSQL_stmt_raise) SqlString() string

func (*PLpgSQL_stmt_raise) String

func (s *PLpgSQL_stmt_raise) String() string

type PLpgSQL_stmt_return

type PLpgSQL_stmt_return struct {
	BaseNode
	Expr *PLpgSQL_expr `json:"expr,omitempty"` // the returned expression, or nil
}

PLpgSQL_stmt_return is `RETURN [expr]` (PG's PLpgSQL_stmt_return). Expr is nil for a bare RETURN. Drops PG's resolved retvarno. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:818-825

func CloneRefOfPLpgSQL_stmt_return

func CloneRefOfPLpgSQL_stmt_return(n *PLpgSQL_stmt_return) *PLpgSQL_stmt_return

CloneRefOfPLpgSQL_stmt_return creates a deep clone of the input.

func NewPLpgSQL_stmt_return

func NewPLpgSQL_stmt_return() *PLpgSQL_stmt_return

func (*PLpgSQL_stmt_return) SqlString

func (s *PLpgSQL_stmt_return) SqlString() string

func (*PLpgSQL_stmt_return) String

func (s *PLpgSQL_stmt_return) String() string

type PLpgSQL_stmt_return_next

type PLpgSQL_stmt_return_next struct {
	BaseNode
	Expr *PLpgSQL_expr `json:"expr,omitempty"` // the row expression
}

PLpgSQL_stmt_return_next is `RETURN NEXT expr` (PG's PLpgSQL_stmt_return_next): append a row to the result set of a set-returning function. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:830-837

func CloneRefOfPLpgSQL_stmt_return_next

func CloneRefOfPLpgSQL_stmt_return_next(n *PLpgSQL_stmt_return_next) *PLpgSQL_stmt_return_next

CloneRefOfPLpgSQL_stmt_return_next creates a deep clone of the input.

func NewPLpgSQL_stmt_return_next

func NewPLpgSQL_stmt_return_next() *PLpgSQL_stmt_return_next

func (*PLpgSQL_stmt_return_next) SqlString

func (s *PLpgSQL_stmt_return_next) SqlString() string

func (*PLpgSQL_stmt_return_next) String

func (s *PLpgSQL_stmt_return_next) String() string

type PLpgSQL_stmt_return_query

type PLpgSQL_stmt_return_query struct {
	BaseNode
	Query    *PLpgSQL_expr   `json:"query,omitempty"`    // static query, or nil
	DynQuery *PLpgSQL_expr   `json:"dynquery,omitempty"` // EXECUTE query string, or nil
	Params   []*PLpgSQL_expr `json:"params,omitempty"`   // USING expressions (dynamic form)
}

PLpgSQL_stmt_return_query is `RETURN QUERY query` (PG's PLpgSQL_stmt_return_query): append a whole query's rows to the result set. Either Query (static) or DynQuery (the `RETURN QUERY EXECUTE expr` form, with optional USING Params) is set. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:842-850

func CloneRefOfPLpgSQL_stmt_return_query

func CloneRefOfPLpgSQL_stmt_return_query(n *PLpgSQL_stmt_return_query) *PLpgSQL_stmt_return_query

CloneRefOfPLpgSQL_stmt_return_query creates a deep clone of the input.

func NewPLpgSQL_stmt_return_query

func NewPLpgSQL_stmt_return_query() *PLpgSQL_stmt_return_query

func (*PLpgSQL_stmt_return_query) SqlString

func (s *PLpgSQL_stmt_return_query) SqlString() string

func (*PLpgSQL_stmt_return_query) String

func (s *PLpgSQL_stmt_return_query) String() string

type PLpgSQL_stmt_rollback

type PLpgSQL_stmt_rollback struct {
	BaseNode
	Chain bool `json:"chain,omitempty"` // AND CHAIN
}

PLpgSQL_stmt_rollback is `ROLLBACK [AND [NO] CHAIN]` (PG's PLpgSQL_stmt_rollback): roll back the current transaction inside a procedure. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:561-567

func CloneRefOfPLpgSQL_stmt_rollback

func CloneRefOfPLpgSQL_stmt_rollback(n *PLpgSQL_stmt_rollback) *PLpgSQL_stmt_rollback

CloneRefOfPLpgSQL_stmt_rollback creates a deep clone of the input.

func NewPLpgSQL_stmt_rollback

func NewPLpgSQL_stmt_rollback() *PLpgSQL_stmt_rollback

func (*PLpgSQL_stmt_rollback) SqlString

func (s *PLpgSQL_stmt_rollback) SqlString() string

func (*PLpgSQL_stmt_rollback) String

func (s *PLpgSQL_stmt_rollback) String() string

type PLpgSQL_stmt_while

type PLpgSQL_stmt_while struct {
	BaseNode
	Label string        `json:"label,omitempty"` // optional loop label
	Cond  *PLpgSQL_expr `json:"cond,omitempty"`  // loop-continuation condition
	Body  []Stmt        `json:"body,omitempty"`  // statements between LOOP and END LOOP
}

PLpgSQL_stmt_while is a `WHILE cond LOOP … END LOOP` (PG's PLpgSQL_stmt_while). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:654-662

func CloneRefOfPLpgSQL_stmt_while

func CloneRefOfPLpgSQL_stmt_while(n *PLpgSQL_stmt_while) *PLpgSQL_stmt_while

CloneRefOfPLpgSQL_stmt_while creates a deep clone of the input.

func NewPLpgSQL_stmt_while

func NewPLpgSQL_stmt_while() *PLpgSQL_stmt_while

func (*PLpgSQL_stmt_while) SqlString

func (s *PLpgSQL_stmt_while) SqlString() string

func (*PLpgSQL_stmt_while) String

func (s *PLpgSQL_stmt_while) String() string

type PLpgSQL_type

type PLpgSQL_type struct {
	BaseNode
	// TypeName is the type as written, e.g. "int", "varchar(10)", "foo%TYPE".
	TypeName string `json:"type_name,omitempty"`
}

PLpgSQL_type is a declared type, reduced to the parse-level text: we capture the type as written and do not resolve it (no OID, no %TYPE/%ROWTYPE resolution — that is variable resolution). Ported from postgres/src/pl/plpgsql/src/plpgsql.h:198-213

func CloneRefOfPLpgSQL_type

func CloneRefOfPLpgSQL_type(n *PLpgSQL_type) *PLpgSQL_type

CloneRefOfPLpgSQL_type creates a deep clone of the input.

func NewPLpgSQL_type

func NewPLpgSQL_type(name string) *PLpgSQL_type

func (*PLpgSQL_type) SqlString

func (t *PLpgSQL_type) SqlString() string

func (*PLpgSQL_type) String

func (t *PLpgSQL_type) String() string

type PLpgSQL_var

type PLpgSQL_var struct {
	BaseNode
	Dno        int           `json:"dno,omitempty"`
	Refname    string        `json:"refname,omitempty"`
	IsConst    bool          `json:"is_const,omitempty"`
	NotNull    bool          `json:"not_null,omitempty"`
	DataType   *PLpgSQL_type `json:"datatype,omitempty"`
	Collate    string        `json:"collate,omitempty"`     // COLLATE name (as written), or "" — PG resolves to an OID
	DefaultVal *PLpgSQL_expr `json:"default_val,omitempty"` // initializer expression, or nil
	// Cursor declaration fields (PG's PLpgSQL_var cursor properties).
	CursorExplicitExpr *PLpgSQL_expr  `json:"cursor_explicit_expr,omitempty"` // bound query; non-nil ⇒ cursor
	CursorOptions      int            `json:"cursor_options,omitempty"`       // FAST_PLAN | scroll flags
	CursorArgs         []*PLpgSQL_var `json:"cursor_args,omitempty"`          // declared cursor args (name + type)
}

PLpgSQL_var is a scalar variable declaration, a parse-level subset: the dno is carried (it is the datum's index in the compiler's datum list, used for resolution), while PG's execution fields (the resolved datatype OID, promise state) are dropped. A CURSOR declaration is also a PLpgSQL_var — a refcursor variable with a bound query — matching PG; the Cursor* fields carry it and CursorExplicitExpr being non-nil marks it. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:309-343

func CloneRefOfPLpgSQL_var

func CloneRefOfPLpgSQL_var(n *PLpgSQL_var) *PLpgSQL_var

CloneRefOfPLpgSQL_var creates a deep clone of the input.

func CloneSliceOfRefOfPLpgSQL_var

func CloneSliceOfRefOfPLpgSQL_var(n []*PLpgSQL_var) []*PLpgSQL_var

CloneSliceOfRefOfPLpgSQL_var creates a deep clone of the input.

func NewPLpgSQL_var

func NewPLpgSQL_var(refname string) *PLpgSQL_var

func (*PLpgSQL_var) DatumNo

func (v *PLpgSQL_var) DatumNo() int

func (*PLpgSQL_var) SetDatumNo

func (v *PLpgSQL_var) SetDatumNo(dno int)

func (*PLpgSQL_var) SqlString

func (v *PLpgSQL_var) SqlString() string

func (*PLpgSQL_var) String

func (v *PLpgSQL_var) String() string

type RaiseLevel

type RaiseLevel int

RaiseLevel is the severity of a RAISE statement — PG's elog_level int (a field of PLpgSQL_stmt_raise, postgres/src/pl/plpgsql/src/plpgsql.h:860). The values match PG exactly so the field maps 1:1 to PG's struct; the keyword form is recovered on deparse. Ported from postgres/src/include/utils/elog.h:31-52 (DEBUG1/LOG/INFO/NOTICE/WARNING/ERROR).

const (
	RAISE_LEVEL_DEBUG     RaiseLevel = 14 // elog.h DEBUG1
	RAISE_LEVEL_LOG       RaiseLevel = 15 // elog.h LOG
	RAISE_LEVEL_INFO      RaiseLevel = 17 // elog.h INFO
	RAISE_LEVEL_NOTICE    RaiseLevel = 18 // elog.h NOTICE
	RAISE_LEVEL_WARNING   RaiseLevel = 19 // elog.h WARNING
	RAISE_LEVEL_EXCEPTION RaiseLevel = 21 // elog.h ERROR (the default)
)

type RaiseOptionType

type RaiseOptionType int

RaiseOptionType selects which USING option a PLpgSQL_raise_option carries (PG's PLpgSQL_raise_option_type). Order and set match PG exactly. Ported from postgres/src/pl/plpgsql/src/plpgsql.h:167-178

const (
	PLPGSQL_RAISEOPTION_ERRCODE RaiseOptionType = iota
	PLPGSQL_RAISEOPTION_MESSAGE
	PLPGSQL_RAISEOPTION_DETAIL
	PLPGSQL_RAISEOPTION_HINT
	PLPGSQL_RAISEOPTION_COLUMN
	PLPGSQL_RAISEOPTION_CONSTRAINT
	PLPGSQL_RAISEOPTION_DATATYPE
	PLPGSQL_RAISEOPTION_TABLE
	PLPGSQL_RAISEOPTION_SCHEMA
)

type RawParseMode

type RawParseMode int

RawParseMode selects how an embedded SQL fragment is parsed. It mirrors PG's RawParseMode enum (postgres/src/include/parser/parser.h), which PG threads into raw_parser(). Our SQL parser does not yet take a mode, so this is metadata recording what kind of fragment a PLpgSQL_expr holds (set by read_sql_construct / read_datatype and their callers). Values and order match PG's enum exactly. Ported from postgres/src/include/parser/parser.h:37-45

const (
	// RAW_PARSE_DEFAULT parses a semicolon-separated list of SQL statements.
	RAW_PARSE_DEFAULT RawParseMode = iota
	// RAW_PARSE_TYPE_NAME parses a single type name.
	RAW_PARSE_TYPE_NAME
	// RAW_PARSE_PLPGSQL_EXPR parses a single PL/pgSQL expression.
	RAW_PARSE_PLPGSQL_EXPR
	// RAW_PARSE_PLPGSQL_ASSIGN1 parses a PL/pgSQL assignment with 1 target.
	RAW_PARSE_PLPGSQL_ASSIGN1
	// RAW_PARSE_PLPGSQL_ASSIGN2 parses a PL/pgSQL assignment with 2 targets.
	RAW_PARSE_PLPGSQL_ASSIGN2
	// RAW_PARSE_PLPGSQL_ASSIGN3 parses a PL/pgSQL assignment with 3 targets.
	RAW_PARSE_PLPGSQL_ASSIGN3
)

type RootNode

type RootNode struct {
	Node
}

RootNode is the root node of the AST when rewriting. It is the first element of the tree.

func CloneRefOfRootNode

func CloneRefOfRootNode(n *RootNode) *RootNode

CloneRefOfRootNode creates a deep clone of the input.

func CloneRootNode

func CloneRootNode(n RootNode) RootNode

CloneRootNode creates a deep clone of the input.

type Stmt

type Stmt interface {
	Node
	// contains filtered or unexported methods
}

Each PLpgSQL_* type in this file ports the same-named PG struct; its "Ported from …plpgsql.h:START-END" comment gives the exact source lines. We keep only the parse-level fields: PG's execution/resolution bookkeeping (cmd_type, stmtid, resolved varno/datum numbers, SPI plans) is dropped, and any field carrying a resolved value holds the source text instead.

Stmt is implemented by every PL/pgSQL statement node — the Go analogue of PG's PLpgSQL_stmt supertype (plpgsql.h:453-464). The unexported marker keeps the set of statements closed to this package.

func CloneSliceOfStmt

func CloneSliceOfStmt(n []Stmt) []Stmt

CloneSliceOfStmt creates a deep clone of the input.

func CloneStmt

func CloneStmt(in Stmt) Stmt

CloneStmt creates a deep clone of the input.

Jump to

Keyboard shortcuts

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