MCPcopy Create free account
hub / github.com/dolthub/doltgresql / call

Function call

server/plpgsql/interpreter_logic.go:86–376  ·  view source on GitHub ↗

call runs the contained operations on the given runner.

(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack)

Source from the content-addressed store, hash-verified

84
85// call runs the contained operations on the given runner.
86func call(ctx *sql.Context, iFunc InterpretedFunction, stack InterpreterStack) (any, error) {
87 // We increment before accessing, so start at -1
88 counter := -1
89 // Run the statements
90 statements := iFunc.GetStatements()
91 for {
92 counter++
93 if counter >= len(statements) {
94 break
95 } else if counter < 0 {
96 panic("negative function counter")
97 }
98
99 operation := statements[counter]
100 switch operation.OpCode {
101 case OpCode_Alias:
102 iv := stack.GetVariable(operation.PrimaryData)
103 if iv.Type == nil {
104 return nil, fmt.Errorf("variable `%s` could not be found", operation.PrimaryData)
105 }
106 stack.NewVariableAlias(operation.Target, operation.PrimaryData)
107 case OpCode_Assign:
108 iv := stack.GetVariable(operation.Target)
109 if iv.Type == nil {
110 return nil, fmt.Errorf("variable `%s` could not be found", operation.Target)
111 }
112 retVal, err := iFunc.QuerySingleReturn(ctx, stack, operation.PrimaryData, iv.Type, operation.SecondaryData)
113 if err != nil {
114 return nil, err
115 }
116 err = stack.SetVariable(ctx, operation.Target, retVal)
117 if err != nil {
118 return nil, err
119 }
120 case OpCode_Declare:
121 typeCollection, err := GetTypesCollectionFromContext(ctx, "")
122 if err != nil {
123 return nil, err
124 }
125
126 // pg_query_go sets PrimaryData for implicit CASE statement variables to
127 // `pg_catalog."integer"`, so we remove double-quotes and extract the schema name.
128 typeName := operation.PrimaryData
129 typeName = strings.ReplaceAll(typeName, `"`, "")
130 schemaName := "pg_catalog"
131 if strings.Contains(typeName, ".") {
132 parts := strings.Split(typeName, ".")
133 schemaName = parts[0]
134 typeName = parts[1]
135 // Check the NonKeyword type names to see if we're looking at
136 // an alias of a type if we're in the pg_catalog schema.
137 // Skip array types (names starting with "_") since their internal
138 // lookup key uses the "_typename" form, not the "typename[]" form
139 // that TypeForNonKeywordTypeName returns.
140 if schemaName == "pg_catalog" && !strings.HasPrefix(typeName, "_") {
141 typ, ok, _ := types.TypeForNonKeywordTypeName(typeName)
142 if ok && typ != nil {
143 typeName = typ.Name()

Callers 2

CallFunction · 0.85
TriggerCallFunction · 0.85

Calls 15

NewTypeFunction · 0.92
evaluteNoticeMessageFunction · 0.85
applyNoticeOptionsFunction · 0.85
convertRowsToRecordsFunction · 0.85
GetVariableMethod · 0.80
NewVariableAliasMethod · 0.80
SetVariableMethod · 0.80
NewVariableWithValueMethod · 0.80
NewVariableMethod · 0.80
IoInputMethod · 0.80
PushScopeMethod · 0.80

Tested by

no test coverage detected