getTargetType returns the evaluated type for this expression. Returns the "anyarray" type if the type combination is invalid.
(ctx *sql.Context, children ...sql.Expression)
| 170 | // getTargetType returns the evaluated type for this expression. |
| 171 | // Returns the "anyarray" type if the type combination is invalid. |
| 172 | func (array *Array) getTargetType(ctx *sql.Context, children ...sql.Expression) (*pgtypes.DoltgresType, error) { |
| 173 | var childrenTypes []*pgtypes.DoltgresType |
| 174 | for _, child := range children { |
| 175 | if child != nil { |
| 176 | childType, ok := child.Type(ctx).(*pgtypes.DoltgresType) |
| 177 | if !ok { |
| 178 | // We use "anyarray" as the indeterminate/invalid type |
| 179 | return pgtypes.AnyArray, nil |
| 180 | } |
| 181 | childrenTypes = append(childrenTypes, childType) |
| 182 | } |
| 183 | } |
| 184 | targetType, _, err := framework.FindCommonType(ctx, childrenTypes) |
| 185 | if err != nil { |
| 186 | return nil, errors.Errorf("ARRAY %s", err.Error()) |
| 187 | } |
| 188 | // If the common type is unresolved (e.g. a user-defined composite type seen before the analyzer runs), |
| 189 | // look it up from the type collection so that ToArrayType can find the array type ID. |
| 190 | if !targetType.IsResolvedType() { |
| 191 | schemaName := targetType.ID.SchemaName() |
| 192 | if schemaName == "" { |
| 193 | schemaName, _ = core.GetCurrentSchema(ctx) |
| 194 | } |
| 195 | if typeColl, tcErr := core.GetTypesCollectionFromContext(ctx, ""); tcErr == nil && typeColl != nil { |
| 196 | if resolved, rErr := typeColl.GetType(ctx, id.NewType(schemaName, targetType.ID.TypeName())); rErr == nil && resolved != nil { |
| 197 | targetType = resolved |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | return targetType.ToArrayType(), nil |
| 202 | } |
no test coverage detected