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

Function createAnonymousCompositeType

server/ast/create_function.go:184–206  ·  view source on GitHub ↗

createAnonymousCompositeType creates a new DoltgresType for the anonymous composite return type for a function, as represented by the |fieldTypes| that were specified in the function definition.

(fieldTypes []tree.SimpleColumnDef)

Source from the content-addressed store, hash-verified

182// type for a function, as represented by the |fieldTypes| that were specified in the function
183// definition.
184func createAnonymousCompositeType(fieldTypes []tree.SimpleColumnDef) *pgtypes.DoltgresType {
185 attrs := make([]pgtypes.CompositeAttribute, len(fieldTypes))
186 for i, fieldType := range fieldTypes {
187 attrs[i] = pgtypes.NewCompositeAttribute(nil, id.Null, fieldType.Name.String(),
188 pgtypes.NewUnresolvedDoltgresTypeFromID(id.NewType("", fieldType.Type.SQLString())), int16(i), "")
189 }
190
191 typeIdString := "table("
192 for i, attr := range attrs {
193 if i > 0 {
194 typeIdString += ","
195 }
196 typeIdString += attr.Name
197 typeIdString += ":"
198 typeIdString += attr.Type.ID.TypeName()
199 }
200 typeIdString += ")"
201
202 // NOTE: there is no schema needed, since these types are anonymous and can't be directly referenced
203 typeId := id.NewType("", typeIdString)
204
205 return pgtypes.NewCompositeType(context.Background(), id.Null, nil, typeId, attrs)
206}
207
208// handleLanguageSQLAs handles parsing SQL definition strings in both CREATE FUNCTION and CREATE PROCEDURE
209// and returns converted the sql statements into vitess statements.

Callers 1

nodeCreateFunctionFunction · 0.85

Calls 4

NewTypeFunction · 0.92
TypeNameMethod · 0.80
StringMethod · 0.65
SQLStringMethod · 0.65

Tested by

no test coverage detected