Documentation
¶
Index ¶
- Constants
- Variables
- func Call(ctx *sql.Context, iFunc InterpretedFunction, runner sql.StatementRunner, ...) (any, error)
- func NormalizeIdentifier(ident string) string
- func NormalizeIdentifierPath(text string) (string, bool)
- func OperationSizeForStatements(stmts []Statement) int32
- func QuoteIdentifier(name string) string
- func TriggerCall(ctx *sql.Context, iFunc InterpretedFunction, runner sql.StatementRunner, ...) (any, error)
- type Assignment
- type Block
- type DynamicExecute
- type ExecuteSQL
- type ForQueryInit
- type ForQueryNext
- type Goto
- type If
- type InterpretedFunction
- type InterpreterOperation
- type InterpreterScopeDetails
- type InterpreterStack
- func (is *InterpreterStack) AdvanceCursor(name string) (sql.Schema, sql.Row, bool)
- func (is *InterpreterStack) BufferReturnQueryResults(results [][]pgtypes.RecordValue)
- func (is *InterpreterStack) CloseCursor(name string)
- func (is *InterpreterStack) Details() *InterpreterScopeDetails
- func (is *InterpreterStack) GetCurrentLabel() string
- func (is *InterpreterStack) GetVariable(name string) InterpreterVariableReference
- func (is *InterpreterStack) GetVariableWithError(name string) (InterpreterVariableReference, error)
- func (is *InterpreterStack) InitCursor(name string, schema sql.Schema, rows []sql.Row)
- func (is *InterpreterStack) ListVariables() map[string][]string
- func (is *InterpreterStack) MarkScopeLoop(advanced bool)
- func (is *InterpreterStack) NewRecord(name string, sch sql.Schema, val sql.Row)
- func (is *InterpreterStack) NewVariable(name string, typ *pgtypes.DoltgresType)
- func (is *InterpreterStack) NewVariableAlias(alias string, target string)
- func (is *InterpreterStack) NewVariableWithValue(name string, typ *pgtypes.DoltgresType, val any)
- func (is *InterpreterStack) PopScope()
- func (is *InterpreterStack) PushScope()
- func (is *InterpreterStack) ReturnOutParamResults() any
- func (is *InterpreterStack) ReturnQueryResults() [][]pgtypes.RecordValue
- func (is *InterpreterStack) Runner() sql.StatementRunner
- func (is *InterpreterStack) ScopeCursor() string
- func (is *InterpreterStack) ScopeLoop() (reportsFound bool, iterated bool)
- func (is *InterpreterStack) SetAnonymousLabel()
- func (is *InterpreterStack) SetFound(ctx *sql.Context, found bool) error
- func (is *InterpreterStack) SetLabel(label string)
- func (is *InterpreterStack) SetOutParams(name []string)
- func (is *InterpreterStack) SetVariable(ctx *sql.Context, name string, val any) error
- func (is *InterpreterStack) UpdateRecord(name string, schema sql.Schema, val sql.Row) error
- type InterpreterVariableReference
- type NoticeLevel
- type NoticeOptionType
- type OpCode
- type Perform
- type Raise
- type Record
- type Return
- type ReturnQuery
- type Statement
- type Variable
Constants ¶
const ( TriggerNewRecordName = "new" TriggerOldRecordName = "old" )
TriggerNewRecordName and TriggerOldRecordName are the names a trigger invocation supplies its row records under. They are the folded form of NEW and OLD, matching how pg_query names them in a parsed function.
const FoundVariableName = "found"
FoundVariableName is the name of the built-in FOUND variable, which PL/pgSQL creates for every function and which reports whether the most recent statement that is defined to set it produced any row. https://www.postgresql.org/docs/15/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS
const OptionLoopCondition = "loop_condition"
OptionLoopCondition is an Options key marking the conditional jump that advances an integer FOR loop. Every kind of loop compiles to the same conditional jump, and PostgreSQL defines a FOR loop as setting FOUND on exit while a WHILE or a plain LOOP leaves it alone, so the two are told apart by this option.
const OptionSetsFound = "sets_found"
OptionSetsFound is an Options key marking an operation that updates the built-in FOUND variable. Static and dynamic execution share an opcode, and PostgreSQL defines a static statement as setting FOUND while a dynamic EXECUTE deliberately leaves it alone, so the two are told apart by this option rather than by their opcode. Operations that always set FOUND do not carry it.
Variables ¶
var ErrRecordHasNoField = errors.NewKind(`record "%s" has no field "%s"`)
ErrRecordHasNoField is returned when a field is read from a RECORD variable that has no such field.
var ErrRecordNotAssigned = errors.NewKind(`record "%s" is not assigned yet`)
ErrRecordNotAssigned is returned when a field is read from a RECORD variable that has not been assigned yet, and therefore has no shape to read a field from.
var ErrVariableNotFound = errors.NewKind("variable `%s` could not be found")
ErrVariableNotFound is returned when a referenced variable does not exist on the stack.
var GetTypesCollectionFromContext func(ctx *sql.Context, database string) (*typecollection.TypeCollection, error)
GetTypesCollectionFromContext is declared within the core package, but is assigned to this variable to work around import cycles.
Functions ¶
func Call ¶
func Call(ctx *sql.Context, iFunc InterpretedFunction, runner sql.StatementRunner, paramsAndReturn []*pgtypes.DoltgresType, vals []any) (any, error)
Call runs the contained operations on the given runner.
func NormalizeIdentifier ¶ added in v1.3.1
NormalizeIdentifier folds a PL/pgSQL identifier the way Postgres does, so that the name a reference is written with and the name a variable was declared with can be compared directly. An unquoted identifier folds to lowercase; a quoted one keeps its case and loses its quotes, with a doubled quote inside standing for a literal one. `MyVar` and `MYVAR` therefore name the same variable, and `"MyVar"` names a different one. pg_query already stores declared names in this form, so normalizing every name we take from raw source text is what puts both sides in the same alphabet.
func NormalizeIdentifierPath ¶ added in v1.3.1
NormalizeIdentifierPath folds a bare reference of the form `name` or `name.field` and reports whether the text was such a reference at all. Some statements, RAISE among them, carry their arguments as raw source text rather than through the expression rewriter, and each one may be either a variable reference or an expression to evaluate. Anything that is not a plain reference is left alone for the caller to evaluate.
func OperationSizeForStatements ¶
OperationSizeForStatements returns the sum of OperationSize for every statement.
func QuoteIdentifier ¶ added in v1.3.1
QuoteIdentifier renders |name| so that it survives NormalizeIdentifier unchanged. Use it when building SQL that refers to a variable whose declared name is already known, since that name may hold capitals that an unquoted mention would fold away.
Types ¶
type Assignment ¶
type Assignment struct {
VariableName string
Expression string
VariableIndex int32 // TODO: figure out what this is used for, probably to get around shadowed variables?
}
Assignment represents an assignment statement.
func (Assignment) AppendOperations ¶
func (stmt Assignment) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Assignment) OperationSize ¶
func (Assignment) OperationSize() int32
OperationSize implements the interface Statement.
type Block ¶
type Block struct {
TriggerNew int32 // When non-zero, indicates that the NEW record exists for use with triggers
TriggerOld int32 // When non-zero, indicates that the OLD record exists for use with triggers
Variables []Variable
Records []Record
Body []Statement
Label string
IsLoop bool
// ContinueTargetOffset gives the loop's next-iteration operation, where a CONTINUE for this loop jumps, as
// an offset from the body's first operation. It applies only when IsLoop is true, and the zero value suits
// WHILE and plain LOOP, whose bodies begin with that step rather than with loop setup.
ContinueTargetOffset int32
}
Block contains a collection of statements, alongside the variables that were declared for the block. Only the top-level block will contain parameter variables.
func (Block) AppendOperations ¶
func (stmt Block) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Block) OperationSize ¶
OperationSize implements the interface Statement.
type DynamicExecute ¶ added in v0.55.4
type DynamicExecute struct {
Query string
Params []string
Target string
// TargetIsRecord states that Target names a single RECORD variable that receives the entire result row,
// rather than a comma-separated list of scalar variables that each receive one column.
TargetIsRecord bool
}
DynamicExecute represents a dynamic SQL statement's execution.
func (DynamicExecute) AppendOperations ¶ added in v0.55.4
func (stmt DynamicExecute) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (DynamicExecute) OperationSize ¶ added in v0.55.4
func (DynamicExecute) OperationSize() int32
OperationSize implements the interface Statement.
type ExecuteSQL ¶ added in v0.17.1
type ExecuteSQL struct {
Statement string
Target string
// TargetIsRecord states that Target names a single RECORD variable that receives the entire result row,
// rather than a comma-separated list of scalar variables that each receive one column.
TargetIsRecord bool
// SetsFound states that the statement updates the built-in FOUND variable. PostgreSQL limits that to
// statements carrying an INTO clause and to data-modifying statements. Everything else leaves FOUND
// as it was, a utility statement such as CREATE TABLE in particular.
SetsFound bool
}
ExecuteSQL represents a standard SQL statement's execution (including the INTO syntax).
func (ExecuteSQL) AppendOperations ¶ added in v0.17.1
func (stmt ExecuteSQL) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (ExecuteSQL) OperationSize ¶ added in v0.17.1
func (ExecuteSQL) OperationSize() int32
OperationSize implements the interface Statement.
type ForQueryInit ¶ added in v0.56.0
ForQueryInit executes a SQL query and stores the result set in a named cursor on the stack. It is the first operation emitted for a FOR record IN query LOOP statement.
func (ForQueryInit) AppendOperations ¶ added in v0.56.0
func (stmt ForQueryInit) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (ForQueryInit) OperationSize ¶ added in v0.56.0
func (ForQueryInit) OperationSize() int32
OperationSize implements the interface Statement.
type ForQueryNext ¶ added in v0.56.0
ForQueryNext fetches the next row from a named cursor and assigns it to a record variable. When the cursor is exhausted it jumps forward by GotoOffset (like an If), exiting the loop.
func (ForQueryNext) AppendOperations ¶ added in v0.56.0
func (stmt ForQueryNext) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (ForQueryNext) OperationSize ¶ added in v0.56.0
func (ForQueryNext) OperationSize() int32
OperationSize implements the interface Statement.
type Goto ¶
Goto jumps to the counter at the given offset.
func (Goto) AppendOperations ¶
func (stmt Goto) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Goto) OperationSize ¶
OperationSize implements the interface Statement.
type If ¶
type If struct {
Condition string
GotoOffset int32
// IsLoopCondition marks this as the conditional jump that advances an integer FOR loop, whose result
// is the only record of the loop having run its body.
IsLoopCondition bool
}
If represents an IF condition, alongside its Goto offset if the condition is true.
func (If) AppendOperations ¶
func (stmt If) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (If) OperationSize ¶
OperationSize implements the interface Statement.
type InterpretedFunction ¶
type InterpretedFunction interface {
ApplyBindings(ctx *sql.Context, stack InterpreterStack, stmt string, bindings []string, enforceType bool) (newStmt string, varFound bool, err error)
GetAllNames() []string
GetOutputParameterNamesAndTypes() ([]string, []*pgtypes.DoltgresType)
GetInputParameterNamesAndTypes() ([]string, []*pgtypes.DoltgresType)
GetReturn() *pgtypes.DoltgresType
GetStatements() []InterpreterOperation
QueryMultiReturn(ctx *sql.Context, stack InterpreterStack, stmt string, bindings []string) (schema sql.Schema, rows []sql.Row, err error)
QueryRowReturn(ctx *sql.Context, stack InterpreterStack, stmt string, targetTypes []*pgtypes.DoltgresType, bindings []string) (row sql.Row, ok bool, err error)
QuerySingleReturn(ctx *sql.Context, stack InterpreterStack, stmt string, targetType *pgtypes.DoltgresType, bindings []string) (val any, err error)
// IsSRF returns whether the function is a set returning function, meaning whether the
// function returns one or more rows as a result.
IsSRF() bool
}
InterpretedFunction is an interface that essentially mirrors the implementation of InterpretedFunction in the framework package.
type InterpreterOperation ¶
type InterpreterOperation struct {
OpCode OpCode
PrimaryData string // This will represent the "main" data, such as the query for PERFORM, expression for IF, etc.
SecondaryData []string // This represents auxiliary data, such as bindings, strictness, etc.
Target string // This is the variable that will store the results (if applicable)
Index int // This is the index that should be set for operations that move the function counter
Options map[string]string // This is extra data for operations that need it
}
InterpreterOperation is an operation that will be performed by the interpreter.
func Parse ¶
func Parse(fullCreateFunctionString string) ([]InterpreterOperation, error)
Parse parses the given CREATE FUNCTION string (which must be the entire string, not just the body) into a Block containing the contents of the body.
type InterpreterScopeDetails ¶
type InterpreterScopeDetails struct {
// contains filtered or unexported fields
}
InterpreterScopeDetails contains all of the details that are relevant to a particular scope.
type InterpreterStack ¶
type InterpreterStack struct {
// contains filtered or unexported fields
}
InterpreterStack represents the working information that an interpreter will use during execution. It is not exactly the same as a stack in the traditional programming sense, but rather is a loose abstraction that serves the same general purpose.
func NewInterpreterStack ¶
func NewInterpreterStack(runner sql.StatementRunner) InterpreterStack
NewInterpreterStack creates a new InterpreterStack.
func (*InterpreterStack) AdvanceCursor ¶ added in v0.56.0
AdvanceCursor returns the next row for the named cursor and advances its index. Returns (schema, row, true) if a row is available, or (nil, nil, false) when exhausted.
func (*InterpreterStack) BufferReturnQueryResults ¶ added in v0.54.10
func (is *InterpreterStack) BufferReturnQueryResults(results [][]pgtypes.RecordValue)
BufferReturnQueryResults buffers |results| from a RETURN QUERY statement so that they can be returned when the function exits. If results from a previous RETURN QUERY call have already been buffered, |results| will be appended.
func (*InterpreterStack) CloseCursor ¶ added in v0.56.0
func (is *InterpreterStack) CloseCursor(name string)
CloseCursor removes the named cursor from the stack.
func (*InterpreterStack) Details ¶
func (is *InterpreterStack) Details() *InterpreterScopeDetails
Details returns the details for the current scope.
func (*InterpreterStack) GetCurrentLabel ¶ added in v0.17.1
func (is *InterpreterStack) GetCurrentLabel() string
GetCurrentLabel traverses the stack (starting from the top) returning the first label found. Returns an empty string if no labels were set.
func (*InterpreterStack) GetVariable ¶
func (is *InterpreterStack) GetVariable(name string) InterpreterVariableReference
GetVariable traverses the stack (starting from the top) to find a variable with a matching name. Returns a reference with a nil type if no variable was found. Use GetVariableWithError when the reason for the failure matters.
func (*InterpreterStack) GetVariableWithError ¶ added in v1.3.0
func (is *InterpreterStack) GetVariableWithError(name string) (InterpreterVariableReference, error)
GetVariableWithError behaves like GetVariable, but explains why the reference could not be resolved rather than returning an empty reference.
func (*InterpreterStack) InitCursor ¶ added in v0.56.0
InitCursor stores the result set for a FOR record IN query LOOP cursor. The cursor is opened in the loop's own scope, which takes ownership of it.
func (*InterpreterStack) ListVariables ¶
func (is *InterpreterStack) ListVariables() map[string][]string
ListVariables returns a map with the names of all variables. The attached slice represents field names for records. Names are keyed exactly as they were declared, which is already the folded form, so a reference matches by being folded the same way rather than by being compared case-insensitively.
func (*InterpreterStack) MarkScopeLoop ¶ added in v1.3.1
func (is *InterpreterStack) MarkScopeLoop(advanced bool)
MarkScopeLoop marks the current scope as a loop's, whose exit reports FOUND, and records whether the loop has just advanced into its body. Only the loop itself knows that it advanced, and it cannot record it in FOUND, which PostgreSQL leaves alone until the loop is left.
func (*InterpreterStack) NewRecord ¶ added in v0.50.1
NewRecord creates a new record in the current scope. If a record with the same name exists in a previous scope, then that record will be shadowed until the current scope exits. A nil |sch| declares a record that has no shape yet, which is what a `DECLARE r RECORD` produces until something is assigned to it. When |sch| is non-nil but |val| is nil, the record has a shape whose every field is NULL, which is what a trigger's OLD record is on an INSERT.
func (*InterpreterStack) NewVariable ¶
func (is *InterpreterStack) NewVariable(name string, typ *pgtypes.DoltgresType)
NewVariable creates a new variable in the current scope. If a variable with the same name exists in a previous scope, then that variable will be shadowed until the current scope exits.
func (*InterpreterStack) NewVariableAlias ¶
func (is *InterpreterStack) NewVariableAlias(alias string, target string)
NewVariableAlias creates a new variable alias, named |alias|, in the current frame of this stack, pointing to the specified |variable|.
func (*InterpreterStack) NewVariableWithValue ¶
func (is *InterpreterStack) NewVariableWithValue(name string, typ *pgtypes.DoltgresType, val any)
NewVariableWithValue creates a new variable in the current scope, setting its initial value to the one given.
func (*InterpreterStack) PopScope ¶
func (is *InterpreterStack) PopScope()
PopScope removes the current scope.
func (*InterpreterStack) PushScope ¶
func (is *InterpreterStack) PushScope()
PushScope creates a new scope.
func (*InterpreterStack) ReturnOutParamResults ¶ added in v0.57.3
func (is *InterpreterStack) ReturnOutParamResults() any
ReturnOutParamResults returns the results in output parameters if there is any from a RETURN QUERY statement.
func (*InterpreterStack) ReturnQueryResults ¶ added in v0.54.10
func (is *InterpreterStack) ReturnQueryResults() [][]pgtypes.RecordValue
ReturnQueryResults returns the buffered results from a RETURN QUERY statement.
func (*InterpreterStack) Runner ¶
func (is *InterpreterStack) Runner() sql.StatementRunner
Runner returns the runner that is being used for the function's execution.
func (*InterpreterStack) ScopeCursor ¶ added in v1.3.1
func (is *InterpreterStack) ScopeCursor() string
ScopeCursor returns the name of the cursor the current scope owns, or an empty string when the scope is not that of a FOR..IN..SELECT loop.
func (*InterpreterStack) ScopeLoop ¶ added in v1.3.1
func (is *InterpreterStack) ScopeLoop() (reportsFound bool, iterated bool)
ScopeLoop reports whether leaving the current scope sets FOUND, and if so whether its loop body ran.
func (*InterpreterStack) SetAnonymousLabel ¶ added in v0.17.1
func (is *InterpreterStack) SetAnonymousLabel()
SetAnonymousLabel sets the label for the current scope to a guaranteed unique value.
func (*InterpreterStack) SetFound ¶ added in v1.3.1
func (is *InterpreterStack) SetFound(ctx *sql.Context, found bool) error
SetFound updates the built-in FOUND variable. Functions compiled before FOUND was supported do not declare it, and a function may shadow the name with a variable of its own, so anything other than the built-in boolean is left alone rather than being overwritten.
func (*InterpreterStack) SetLabel ¶ added in v0.17.1
func (is *InterpreterStack) SetLabel(label string)
SetLabel sets the label for the current scope.
func (*InterpreterStack) SetOutParams ¶ added in v0.57.3
func (is *InterpreterStack) SetOutParams(name []string)
SetOutParams sets the output parameter names slice for the stack.
func (*InterpreterStack) SetVariable ¶
SetVariable sets the first variable found, with a matching name, to the value given. This does not ensure that the value matches the expectations of the type, so it should be validated before this is called. Returns an error if the variable cannot be found.
func (*InterpreterStack) UpdateRecord ¶ added in v0.56.0
UpdateRecord finds the named variable and sets its schema and row value. A nil |val| gives the record the shape of |schema| with every field NULL, which is what PostgreSQL does when an INTO query matches no rows.
type InterpreterVariableReference ¶ added in v0.50.1
type InterpreterVariableReference struct {
Type *pgtypes.DoltgresType
Value *any
}
InterpreterVariableReference is a reference to a variable that lives on the stack. If the type is not null, then it is valid to dereference the value for assignment. We make use of references rather than directly interacting with the variables as this allows for interacting with sections of aggregate types (such as record) as well as normal variable interaction.
type NoticeLevel ¶ added in v0.18.0
type NoticeLevel uint8
NoticeLevel represents the severity, or level, of a notice created by a RAISE statement.
const ( NoticeLevelDebug NoticeLevel = 14 NoticeLevelLog NoticeLevel = 15 NoticeLevelInfo NoticeLevel = 17 NoticeLevelNotice NoticeLevel = 18 NoticeLevelWarning NoticeLevel = 19 NoticeLevelException NoticeLevel = 21 )
func (NoticeLevel) String ¶ added in v0.18.0
func (nl NoticeLevel) String() string
String returns a string representation of this NoticeLevel.
type NoticeOptionType ¶ added in v0.18.0
type NoticeOptionType uint8
NoticeOptionType represents the type of option specified for a notice in the USING clause of a RAISE statement.
const ( NoticeOptionTypeErrCode NoticeOptionType = 0 NoticeOptionTypeMessage NoticeOptionType = 1 NoticeOptionTypeDetail NoticeOptionType = 2 NoticeOptionTypeHint NoticeOptionType = 3 NoticeOptionTypeConstraint NoticeOptionType = 5 NoticeOptionTypeDataType NoticeOptionType = 6 NoticeOptionTypeTable NoticeOptionType = 7 NoticeOptionTypeSchema NoticeOptionType = 8 )
type OpCode ¶
type OpCode uint16
OpCode states the operation to be performed. Most operations have a direct analogue to a Pl/pgSQL operation, however some exist only in Doltgres (specific to our interpreter implementation).
const ( // New OpCode values MUST be added to the END of this list! // Function OpCodes are persisted to disk, so these values MUST be stable across Doltgres versions. OpCode_Alias OpCode = 0 // https://www.postgresql.org/docs/15/plpgsql-declarations.html#PLPGSQL-DECLARATION-ALIAS OpCode_Assign OpCode = 1 // https://www.postgresql.org/docs/15/plpgsql-statements.html#PLPGSQL-STATEMENTS-ASSIGNMENT OpCode_Case OpCode = 2 // https://www.postgresql.org/docs/15/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS OpCode_Declare OpCode = 3 // https://www.postgresql.org/docs/15/plpgsql-declarations.html OpCode_DeleteInto OpCode = 4 // https://www.postgresql.org/docs/15/plpgsql-statements.html OpCode_Exception OpCode = 5 // https://www.postgresql.org/docs/15/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING OpCode_Execute OpCode = 6 // Executing a standard SQL statement (expects no rows returned unless Target is specified) OpCode_Get OpCode = 7 // https://www.postgresql.org/docs/15/plpgsql-statements.html#PLPGSQL-STATEMENTS-DIAGNOSTICS OpCode_Goto OpCode = 8 // All control-flow structures can be represented using Goto OpCode_If OpCode = 9 // https://www.postgresql.org/docs/15/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS OpCode_InsertInto OpCode = 10 // https://www.postgresql.org/docs/15/plpgsql-statements.html OpCode_Perform OpCode = 11 // https://www.postgresql.org/docs/15/plpgsql-statements.html OpCode_Raise OpCode = 12 // https://www.postgresql.org/docs/15/plpgsql-errors-and-messages.html OpCode_Return OpCode = 13 // https://www.postgresql.org/docs/15/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING OpCode_ScopeBegin OpCode = 14 // This is used for scope control, specific to Doltgres OpCode_ScopeEnd OpCode = 15 // This is used for scope control, specific to Doltgres OpCode_SelectInto OpCode = 16 // https://www.postgresql.org/docs/15/plpgsql-statements.html OpCode_UpdateInto OpCode = 17 // https://www.postgresql.org/docs/15/plpgsql-statements.html OpCode_ReturnQuery OpCode = 18 // https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-STATEMENTS-RETURNING-RETURN-NEXT OpCode_ForQueryInit OpCode = 19 // Initialize a cursor for FOR record IN query LOOP OpCode_ForQueryNext OpCode = 20 // Advance cursor and assign next row to record, or jump to exit OpCode_DeclareRecord OpCode = 21 // Declares a RECORD variable, which has no shape until it is assigned OpCode_ExecuteInto OpCode = 22 // Executing a SQL statement whose first result row is assigned to a RECORD )
type Perform ¶ added in v0.17.1
type Perform struct {
Statement string
}
Perform represents a PERFORM statement.
func (Perform) AppendOperations ¶ added in v0.17.1
func (stmt Perform) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Perform) OperationSize ¶ added in v0.17.1
OperationSize implements the interface Statement.
type Raise ¶ added in v0.18.0
Raise represents a RAISE statement
func (Raise) AppendOperations ¶ added in v0.18.0
func (r Raise) AppendOperations(ops *[]InterpreterOperation, _ *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Raise) OperationSize ¶ added in v0.18.0
OperationSize implements the interface Statement.
type Record ¶ added in v0.50.1
type Record struct {
Name string
Fields []string
// IsTriggerRecord is true for the NEW and OLD records of a trigger function. Those are created by the
// trigger invocation rather than by the function body, so they are not declared when the block is entered.
IsTriggerRecord bool
}
Record represents a record (along with known fields for future access). These are exclusively found within Block.
func (Record) IsDeclared ¶ added in v1.3.0
IsDeclared returns whether entering the record's block should declare it. Trigger records are supplied by the trigger invocation, and PL/pgSQL leaves a record's name empty when it is only referenced internally.
type Return ¶
type Return struct {
Expression string
}
Return represents a RETURN statement.
func (Return) AppendOperations ¶
func (stmt Return) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (Return) OperationSize ¶
OperationSize implements the interface Statement.
type ReturnQuery ¶ added in v0.54.10
type ReturnQuery struct {
Query string
}
ReturnQuery represents a RETURN QUERY statement.
func (ReturnQuery) AppendOperations ¶ added in v0.54.10
func (r ReturnQuery) AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
AppendOperations implements the interface Statement.
func (ReturnQuery) OperationSize ¶ added in v0.54.10
func (r ReturnQuery) OperationSize() int32
OperationSize implements the interface Statement.
type Statement ¶
type Statement interface {
// OperationSize reports the number of operations that the statement will convert to.
OperationSize() int32
// AppendOperations adds the statement to the operation slice.
AppendOperations(ops *[]InterpreterOperation, stack *InterpreterStack) error
}
Statement represents a PL/pgSQL statement.