plpgsqltree

package
v0.25.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 6 Imported by: 1 module, 2 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Assert

type Assert struct {
	StatementImpl
	Condition Expr
	Message   Expr
}

stmt_assert

func (*Assert) CopyNode

func (s *Assert) CopyNode() *Assert

func (*Assert) Format

func (s *Assert) Format(ctx *tree.FmtCtx)

func (*Assert) PlpgSQLStatementTag

func (s *Assert) PlpgSQLStatementTag() string

func (*Assert) WalkStmt

func (s *Assert) WalkStmt(visitor StatementVisitor) Statement

type Assignment

type Assignment struct {
	StatementImpl
	Var   Variable
	Value Expr

	// Indirection is the optional name of a field in a composite variable. For
	// example, in the assignment "foo.bar := 1", Indirection would be "bar".
	Indirection tree.Name
}

stmt_assign

func (*Assignment) CopyNode

func (s *Assignment) CopyNode() *Assignment

func (*Assignment) Format

func (s *Assignment) Format(ctx *tree.FmtCtx)

func (*Assignment) PlpgSQLStatementTag

func (s *Assignment) PlpgSQLStatementTag() string

func (*Assignment) WalkStmt

func (s *Assignment) WalkStmt(visitor StatementVisitor) Statement

type Block

type Block struct {
	StatementImpl
	Label      string
	Decls      []Statement
	Body       []Statement
	Exceptions []Exception
}

pl_block

func (*Block) CopyNode

func (s *Block) CopyNode() *Block

func (*Block) Format

func (s *Block) Format(ctx *tree.FmtCtx)

func (*Block) PlpgSQLStatementTag

func (s *Block) PlpgSQLStatementTag() string

func (*Block) WalkStmt

func (s *Block) WalkStmt(visitor StatementVisitor) Statement

type Call

type Call struct {
	StatementImpl
	Proc *tree.FuncExpr
}

stmt_call

func (*Call) CopyNode

func (s *Call) CopyNode() *Call

func (*Call) Format

func (s *Call) Format(ctx *tree.FmtCtx)

func (*Call) PlpgSQLStatementTag

func (s *Call) PlpgSQLStatementTag() string

func (*Call) WalkStmt

func (s *Call) WalkStmt(visitor StatementVisitor) Statement

type Case

type Case struct {
	StatementImpl
	// TODO(drewk): Change to Expr
	TestExpr     string
	Var          Variable
	CaseWhenList []*CaseWhen
	HaveElse     bool
	ElseStmts    []Statement
}

stmt_case

func (*Case) CopyNode

func (s *Case) CopyNode() *Case

func (*Case) Format

func (s *Case) Format(ctx *tree.FmtCtx)

TODO(drewk): fix the whitespace/newline formatting for CASE (see the stmt_case test file).

func (*Case) PlpgSQLStatementTag

func (s *Case) PlpgSQLStatementTag() string

func (*Case) WalkStmt

func (s *Case) WalkStmt(visitor StatementVisitor) Statement

type CaseWhen

type CaseWhen struct {
	StatementImpl
	// TODO(drewk): Change to Expr
	Expr  string
	Stmts []Statement
}

func (*CaseWhen) CopyNode

func (s *CaseWhen) CopyNode() *CaseWhen

func (*CaseWhen) Format

func (s *CaseWhen) Format(ctx *tree.FmtCtx)

func (*CaseWhen) PlpgSQLStatementTag

func (s *CaseWhen) PlpgSQLStatementTag() string

func (*CaseWhen) WalkStmt

func (s *CaseWhen) WalkStmt(visitor StatementVisitor) Statement

type Close

type Close struct {
	StatementImpl
	CurVar Variable
}

stmt_close

func (*Close) Format

func (s *Close) Format(ctx *tree.FmtCtx)

func (*Close) PlpgSQLStatementTag

func (s *Close) PlpgSQLStatementTag() string

func (*Close) WalkStmt

func (s *Close) WalkStmt(visitor StatementVisitor) Statement

type Condition

type Condition struct {
	SqlErrState string
	SqlErrName  string
}

type Continue

type Continue struct {
	StatementImpl
	Label     string
	Condition Expr
}

stmt_continue

func (*Continue) CopyNode

func (s *Continue) CopyNode() *Continue

func (*Continue) Format

func (s *Continue) Format(ctx *tree.FmtCtx)

func (*Continue) PlpgSQLStatementTag

func (s *Continue) PlpgSQLStatementTag() string

func (*Continue) WalkStmt

func (s *Continue) WalkStmt(visitor StatementVisitor) Statement

type CursorDeclaration

type CursorDeclaration struct {
	StatementImpl
	Name        Variable
	Scroll      tree.CursorScrollOption
	Query       tree.Statement
	Annotations *tree.Annotations
}

func (*CursorDeclaration) CopyNode

func (s *CursorDeclaration) CopyNode() *CursorDeclaration

func (*CursorDeclaration) Format

func (s *CursorDeclaration) Format(ctx *tree.FmtCtx)

func (*CursorDeclaration) PlpgSQLStatementTag

func (s *CursorDeclaration) PlpgSQLStatementTag() string

func (*CursorDeclaration) WalkStmt

func (s *CursorDeclaration) WalkStmt(visitor StatementVisitor) Statement

type Declaration

type Declaration struct {
	StatementImpl
	Var      Variable
	Constant bool
	Typ      tree.ResolvableTypeReference
	Collate  string
	NotNull  bool
	Expr     Expr
}

decl_stmt

func (*Declaration) CopyNode

func (s *Declaration) CopyNode() *Declaration

func (*Declaration) Format

func (s *Declaration) Format(ctx *tree.FmtCtx)

func (*Declaration) PlpgSQLStatementTag

func (s *Declaration) PlpgSQLStatementTag() string

func (*Declaration) WalkStmt

func (s *Declaration) WalkStmt(visitor StatementVisitor) Statement

type DoBlock added in v0.25.2

type DoBlock struct {
	StatementImpl

	// Block is the code block that defines the logic of the DO statement.
	Block *Block
}

stmt_do

func (*DoBlock) CopyNode added in v0.25.2

func (s *DoBlock) CopyNode() *DoBlock

func (*DoBlock) Format added in v0.25.2

func (s *DoBlock) Format(ctx *tree.FmtCtx)

func (*DoBlock) IsDoBlockBody added in v0.25.2

func (s *DoBlock) IsDoBlockBody()

func (*DoBlock) PlpgSQLStatementTag added in v0.25.2

func (s *DoBlock) PlpgSQLStatementTag() string

func (*DoBlock) VisitBody added in v0.25.2

func (s *DoBlock) VisitBody(v tree.Visitor) tree.DoBlockBody

func (*DoBlock) WalkStmt added in v0.25.2

func (s *DoBlock) WalkStmt(visitor StatementVisitor) Statement

type DynamicExecute

type DynamicExecute struct {
	StatementImpl
	Query  string
	Into   bool
	Strict bool
	Target Variable
	Params []Expr
}

stmt_dynexecute TODO(chengxiong): query should be a better expression type.

func (*DynamicExecute) CopyNode

func (s *DynamicExecute) CopyNode() *DynamicExecute

func (*DynamicExecute) Format

func (s *DynamicExecute) Format(ctx *tree.FmtCtx)

func (*DynamicExecute) PlpgSQLStatementTag

func (s *DynamicExecute) PlpgSQLStatementTag() string

func (*DynamicExecute) WalkStmt

func (s *DynamicExecute) WalkStmt(visitor StatementVisitor) Statement

type ElseIf

type ElseIf struct {
	StatementImpl
	Condition Expr
	Stmts     []Statement
}

func (*ElseIf) CopyNode

func (s *ElseIf) CopyNode() *ElseIf

func (*ElseIf) Format

func (s *ElseIf) Format(ctx *tree.FmtCtx)

func (*ElseIf) PlpgSQLStatementTag

func (s *ElseIf) PlpgSQLStatementTag() string

func (*ElseIf) WalkStmt

func (s *ElseIf) WalkStmt(visitor StatementVisitor) Statement

type Exception

type Exception struct {
	StatementImpl
	Conditions []Condition
	Action     []Statement
}

func (*Exception) CopyNode

func (s *Exception) CopyNode() *Exception

func (*Exception) Format

func (s *Exception) Format(ctx *tree.FmtCtx)

func (*Exception) PlpgSQLStatementTag

func (s *Exception) PlpgSQLStatementTag() string

func (*Exception) WalkStmt

func (s *Exception) WalkStmt(visitor StatementVisitor) Statement

type Execute

type Execute struct {
	StatementImpl
	SqlStmt     tree.Statement
	Strict      bool // INTO STRICT flag
	Target      []Variable
	Annotations *tree.Annotations
}

stmt_execsql

func (*Execute) CopyNode

func (s *Execute) CopyNode() *Execute

func (*Execute) Format

func (s *Execute) Format(ctx *tree.FmtCtx)

func (*Execute) PlpgSQLStatementTag

func (s *Execute) PlpgSQLStatementTag() string

func (*Execute) WalkStmt

func (s *Execute) WalkStmt(visitor StatementVisitor) Statement

type Exit

type Exit struct {
	StatementImpl
	Label     string
	Condition Expr
}

stmt_exit

func (*Exit) CopyNode

func (s *Exit) CopyNode() *Exit

func (*Exit) Format

func (s *Exit) Format(ctx *tree.FmtCtx)

func (*Exit) PlpgSQLStatementTag

func (s *Exit) PlpgSQLStatementTag() string

func (*Exit) WalkStmt

func (s *Exit) WalkStmt(visitor StatementVisitor) Statement

type Expr

type Expr = tree.Expr

type Fetch

type Fetch struct {
	StatementImpl
	Cursor      tree.CursorStmt
	Target      []Variable
	IsMove      bool
	Annotations *tree.Annotations
}

stmt_fetch stmt_move (where IsMove = true)

func (*Fetch) Format

func (s *Fetch) Format(ctx *tree.FmtCtx)

func (*Fetch) PlpgSQLStatementTag

func (s *Fetch) PlpgSQLStatementTag() string

func (*Fetch) WalkStmt

func (s *Fetch) WalkStmt(visitor StatementVisitor) Statement

type ForEachArray

type ForEachArray struct {
	StatementImpl
	Label string
	Var   *Variable
	Slice int // TODO(drewk): not sure what this is
	Expr  Expr
	Body  []Statement
}

stmt_foreach_a

func (*ForEachArray) Format

func (s *ForEachArray) Format(ctx *tree.FmtCtx)

func (*ForEachArray) PlpgSQLStatementTag

func (s *ForEachArray) PlpgSQLStatementTag() string

func (*ForEachArray) WalkStmt

func (s *ForEachArray) WalkStmt(visitor StatementVisitor) Statement

type ForLoop added in v0.25.2

type ForLoop struct {
	StatementImpl
	Label   string
	Target  []Variable
	Control ForLoopControl
	Body    []Statement
}

stmt_for

func (*ForLoop) CopyNode added in v0.25.2

func (s *ForLoop) CopyNode() *ForLoop

func (*ForLoop) Format added in v0.25.2

func (s *ForLoop) Format(ctx *tree.FmtCtx)

func (*ForLoop) PlpgSQLStatementTag added in v0.25.2

func (s *ForLoop) PlpgSQLStatementTag() string

func (*ForLoop) WalkStmt added in v0.25.2

func (s *ForLoop) WalkStmt(visitor StatementVisitor) Statement

type ForLoopControl added in v0.25.2

type ForLoopControl interface {
	Format(ctx *tree.FmtCtx)
	// contains filtered or unexported methods
}

ForLoopControl is an interface covering the loop control structures for the integer range, query, and cursor FOR loops.

type GetDiagnostics

type GetDiagnostics struct {
	StatementImpl
	IsStacked bool
	DiagItems GetDiagnosticsItemList // TODO(drewk): what is this?
}

stmt_getdiag

func (*GetDiagnostics) Format

func (s *GetDiagnostics) Format(ctx *tree.FmtCtx)

func (*GetDiagnostics) PlpgSQLStatementTag

func (s *GetDiagnostics) PlpgSQLStatementTag() string

func (*GetDiagnostics) WalkStmt

func (s *GetDiagnostics) WalkStmt(visitor StatementVisitor) Statement

type GetDiagnosticsItem

type GetDiagnosticsItem struct {
	Kind GetDiagnosticsKind
	// TODO(drewk): TargetName is temporary -- should be removed and use Target.
	TargetName string
	Target     int // where to assign it?
}

func (*GetDiagnosticsItem) Format

func (s *GetDiagnosticsItem) Format(ctx *tree.FmtCtx)

type GetDiagnosticsItemList

type GetDiagnosticsItemList []*GetDiagnosticsItem

type GetDiagnosticsKind

type GetDiagnosticsKind int

GetDiagnosticsKind represents the type of error diagnostic item in stmt_getdiag.

const (
	// GetDiagnosticsRowCount returns the number of rows processed by the recent
	// SQL command.
	GetDiagnosticsRowCount GetDiagnosticsKind = iota
	// GetDiagnosticsContext returns text describing the current call stack.
	GetDiagnosticsContext
	// GetDiagnosticsErrorContext returns text describing the exception's
	// callstack.
	GetDiagnosticsErrorContext
	// GetDiagnosticsErrorDetail returns the exceptions detail message.
	GetDiagnosticsErrorDetail
	// GetDiagnosticsErrorHint returns the exceptions hint message.
	GetDiagnosticsErrorHint
	// GetDiagnosticsReturnedSQLState returns the SQLSTATE error code related to
	// the exception.
	GetDiagnosticsReturnedSQLState
	// GetDiagnosticsColumnName returns the column name related to the exception.
	GetDiagnosticsColumnName
	// GetDiagnosticsConstraintName returns the constraint name related to
	// the exception.
	GetDiagnosticsConstraintName
	// GetDiagnosticsDatatypeName returns the data type name related to the
	// exception.
	GetDiagnosticsDatatypeName
	// GetDiagnosticsMessageText returns the exceptions primary message.
	GetDiagnosticsMessageText
	// GetDiagnosticsTableName returns the name of the table related to the
	// exception.
	GetDiagnosticsTableName
	// GetDiagnosticsSchemaName returns the name of the schema related to the
	// exception.
	GetDiagnosticsSchemaName
)

func (GetDiagnosticsKind) String

func (k GetDiagnosticsKind) String() string

String implements the fmt.Stringer interface.

type If

type If struct {
	StatementImpl
	Condition  Expr
	ThenBody   []Statement
	ElseIfList []ElseIf
	ElseBody   []Statement
}

stmt_if

func (*If) CopyNode

func (s *If) CopyNode() *If

func (*If) Format

func (s *If) Format(ctx *tree.FmtCtx)

func (*If) PlpgSQLStatementTag

func (s *If) PlpgSQLStatementTag() string

func (*If) WalkStmt

func (s *If) WalkStmt(visitor StatementVisitor) Statement

type IntForLoopControl added in v0.25.2

type IntForLoopControl struct {
	Reverse bool
	Lower   Expr
	Upper   Expr
	Step    Expr
}

func (*IntForLoopControl) Format added in v0.25.2

func (c *IntForLoopControl) Format(ctx *tree.FmtCtx)

type Loop

type Loop struct {
	StatementImpl
	Label string
	Body  []Statement
}

stmt_loop

func (*Loop) CopyNode

func (s *Loop) CopyNode() *Loop

func (*Loop) Format

func (s *Loop) Format(ctx *tree.FmtCtx)

func (*Loop) PlpgSQLStatementTag

func (s *Loop) PlpgSQLStatementTag() string

func (*Loop) WalkStmt

func (s *Loop) WalkStmt(visitor StatementVisitor) Statement

type Null

type Null struct {
	StatementImpl
}

stmt_null

func (*Null) Format

func (s *Null) Format(ctx *tree.FmtCtx)

func (*Null) PlpgSQLStatementTag

func (s *Null) PlpgSQLStatementTag() string

func (*Null) WalkStmt

func (s *Null) WalkStmt(visitor StatementVisitor) Statement

type Open

type Open struct {
	StatementImpl
	CurVar      Variable
	Scroll      tree.CursorScrollOption
	Query       tree.Statement
	Annotations *tree.Annotations
}

stmt_open

func (*Open) CopyNode

func (s *Open) CopyNode() *Open

func (*Open) Format

func (s *Open) Format(ctx *tree.FmtCtx)

func (*Open) PlpgSQLStatementTag

func (s *Open) PlpgSQLStatementTag() string

func (*Open) WalkStmt

func (s *Open) WalkStmt(visitor StatementVisitor) Statement

type Perform

type Perform struct {
	StatementImpl
	Expr Expr
}

stmt_perform

func (*Perform) Format

func (s *Perform) Format(ctx *tree.FmtCtx)

func (*Perform) PlpgSQLStatementTag

func (s *Perform) PlpgSQLStatementTag() string

func (*Perform) WalkStmt

func (s *Perform) WalkStmt(visitor StatementVisitor) Statement

type Raise

type Raise struct {
	StatementImpl
	LogLevel string
	Code     string
	CodeName string
	Message  string
	Params   []Expr
	Options  []RaiseOption
}

stmt_raise

func (*Raise) CopyNode

func (s *Raise) CopyNode() *Raise

func (*Raise) Format

func (s *Raise) Format(ctx *tree.FmtCtx)

func (*Raise) PlpgSQLStatementTag

func (s *Raise) PlpgSQLStatementTag() string

func (*Raise) WalkStmt

func (s *Raise) WalkStmt(visitor StatementVisitor) Statement

type RaiseOption

type RaiseOption struct {
	OptType string
	Expr    Expr
}

func (*RaiseOption) Format

func (s *RaiseOption) Format(ctx *tree.FmtCtx)

type Return

type Return struct {
	StatementImpl
	Expr Expr
}

stmt_return

func (*Return) CopyNode

func (s *Return) CopyNode() *Return

func (*Return) Format

func (s *Return) Format(ctx *tree.FmtCtx)

func (*Return) PlpgSQLStatementTag

func (s *Return) PlpgSQLStatementTag() string

func (*Return) WalkStmt

func (s *Return) WalkStmt(visitor StatementVisitor) Statement

type ReturnNext

type ReturnNext struct {
	StatementImpl
	Expr Expr
}

func (*ReturnNext) CopyNode added in v0.25.2

func (s *ReturnNext) CopyNode() *ReturnNext

func (*ReturnNext) Format

func (s *ReturnNext) Format(ctx *tree.FmtCtx)

func (*ReturnNext) PlpgSQLStatementTag

func (s *ReturnNext) PlpgSQLStatementTag() string

func (*ReturnNext) WalkStmt

func (s *ReturnNext) WalkStmt(visitor StatementVisitor) Statement

type ReturnQuery

type ReturnQuery struct {
	StatementImpl
	SqlStmt     tree.Statement
	Annotations *tree.Annotations
}

func (*ReturnQuery) CopyNode added in v0.25.2

func (s *ReturnQuery) CopyNode() *ReturnQuery

func (*ReturnQuery) Format

func (s *ReturnQuery) Format(ctx *tree.FmtCtx)

func (*ReturnQuery) PlpgSQLStatementTag

func (s *ReturnQuery) PlpgSQLStatementTag() string

func (*ReturnQuery) WalkStmt

func (s *ReturnQuery) WalkStmt(visitor StatementVisitor) Statement

type SQLStmtVisitor added in v0.25.2

type SQLStmtVisitor struct {
	Fn      tree.SimpleVisitFn
	Visitor tree.Visitor
	Err     error
}

SQLStmtVisitor applies a visitor to every SQL statement and expression found while walking the PL/pgSQL AST. SQLStmtVisitor supports using tree.v.visitExprFn for callers that don't need the full Visitor interface.

*Only one of Fn or Visitor can be set.*

func (*SQLStmtVisitor) Visit added in v0.25.2

func (v *SQLStmtVisitor) Visit(stmt Statement) (newStmt Statement, recurse bool)

type Statement

type Statement interface {
	tree.NodeFormatter
	GetLineNo() int
	GetStmtID() uint

	WalkStmt(StatementVisitor) Statement
	PlpgSQLStatementTag() string
	// contains filtered or unexported methods
}

func Walk

func Walk(v StatementVisitor, stmt Statement) Statement

Walk traverses the plpgsql statement.

type StatementImpl

type StatementImpl struct {
	// TODO(drewk): figure out how to get line number from scanner.
	LineNo int
	/*
	 * Unique statement ID in this function (starting at 1; 0 is invalid/not
	 * set).  This can be used by a profiler as the index for an array of
	 * per-statement metrics.
	 */
	// TODO(drewk): figure out how to get statement id from parser.
	StmtID uint
}

func (*StatementImpl) GetLineNo

func (s *StatementImpl) GetLineNo() int

func (*StatementImpl) GetStmtID

func (s *StatementImpl) GetStmtID() uint

type StatementVisitor

type StatementVisitor interface {
	// Visit is called during a statement walk. If recurse is false for a given
	// node, the node's children (if any) will not be visited.
	Visit(stmt Statement) (newStmt Statement, recurse bool)
}

StatementVisitor defines methods that are called plpgsql statements during a statement walk.

type TransactionControl added in v0.25.2

type TransactionControl struct {
	StatementImpl
	Rollback bool
	Chain    bool
}

stmt_commit and stmt_rollback

func (*TransactionControl) Format added in v0.25.2

func (s *TransactionControl) Format(ctx *tree.FmtCtx)

func (*TransactionControl) PlpgSQLStatementTag added in v0.25.2

func (s *TransactionControl) PlpgSQLStatementTag() string

func (*TransactionControl) WalkStmt added in v0.25.2

func (s *TransactionControl) WalkStmt(visitor StatementVisitor) Statement

type TypeRefVisitor added in v0.25.2

type TypeRefVisitor struct {
	Fn  func(typ tree.ResolvableTypeReference) (newTyp tree.ResolvableTypeReference, err error)
	Err error
}

TypeRefVisitor calls the given replace function on each type reference contained in the visited PLpgSQL statements. Note that this currently only includes `Declaration`. SQL statements and expressions are not visited.

func (*TypeRefVisitor) Visit added in v0.25.2

func (v *TypeRefVisitor) Visit(stmt Statement) (newStmt Statement, recurse bool)

type Variable

type Variable = tree.Name

type While

type While struct {
	StatementImpl
	Label     string
	Condition Expr
	Body      []Statement
}

stmt_while

func (*While) CopyNode

func (s *While) CopyNode() *While

func (*While) Format

func (s *While) Format(ctx *tree.FmtCtx)

func (*While) PlpgSQLStatementTag

func (s *While) PlpgSQLStatementTag() string

func (*While) WalkStmt

func (s *While) WalkStmt(visitor StatementVisitor) Statement

Jump to

Keyboard shortcuts

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