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)
| 182 | // type for a function, as represented by the |fieldTypes| that were specified in the function |
| 183 | // definition. |
| 184 | func 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. |
no test coverage detected