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

Function dropFunction

server/node/drop_function.go:111–143  ·  view source on GitHub ↗
(ctx *sql.Context, funcColl *functions.Collection, fn *RoutineWithParams, ifExists bool)

Source from the content-addressed store, hash-verified

109}
110
111func dropFunction(ctx *sql.Context, funcColl *functions.Collection, fn *RoutineWithParams, ifExists bool) error {
112 // TODO: provide db
113 schema, err := core.GetSchemaName(ctx, nil, fn.SchemaName)
114 if err != nil {
115 return err
116 }
117 var funcId = id.NewFunction(schema, fn.RoutineName)
118 if len(fn.Args) == 0 {
119 funcs, err := funcColl.GetFunctionOverloads(ctx, funcId)
120 if err != nil {
121 return err
122 }
123 if len(funcs) == 1 {
124 funcId = funcs[0].ID
125 } else if len(funcs) > 1 {
126 funcExists := funcColl.HasFunction(ctx, funcId)
127 if !funcExists {
128 return errors.Errorf(`function name "%s" is not unique`, fn.RoutineName)
129 }
130 }
131 } else {
132 var argTypes = make([]id.Type, len(fn.Args))
133 for i, arg := range fn.Args {
134 argTypes[i] = arg.Type.ID
135 }
136 funcId = id.NewFunction(schema, fn.RoutineName, argTypes...)
137 }
138 funcExists := funcColl.HasFunction(ctx, funcId)
139 if !funcExists && ifExists {
140 return nil
141 }
142 return funcColl.DropFunction(ctx, funcId)
143}

Callers 1

RowIterMethod · 0.85

Calls 6

GetSchemaNameFunction · 0.92
NewFunctionFunction · 0.92
GetFunctionOverloadsMethod · 0.80
HasFunctionMethod · 0.80
DropFunctionMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected