TypeCheck implements the Expr interface.
( ctx context.Context, semaCtx *SemaContext, desired *types.T, )
| 527 | |
| 528 | // TypeCheck implements the Expr interface. |
| 529 | func (expr *CollateExpr) TypeCheck( |
| 530 | ctx context.Context, semaCtx *SemaContext, desired *types.T, |
| 531 | ) (TypedExpr, error) { |
| 532 | _, err := language.Parse(expr.Locale) |
| 533 | if err != nil { |
| 534 | return nil, pgerror.Wrapf(err, pgcode.InvalidParameterValue, |
| 535 | "invalid locale %s", expr.Locale) |
| 536 | } |
| 537 | subExpr, err := expr.Expr.TypeCheck(ctx, semaCtx, types.String) |
| 538 | if err != nil { |
| 539 | return nil, err |
| 540 | } |
| 541 | t := subExpr.ResolvedType() |
| 542 | if types.IsStringType(t) || t.Family() == types.UnknownFamily { |
| 543 | expr.Expr = subExpr |
| 544 | expr.typ = types.MakeCollatedString(types.String, expr.Locale) |
| 545 | return expr, nil |
| 546 | } |
| 547 | return nil, pgerror.Newf(pgcode.DatatypeMismatch, |
| 548 | "incompatible type for COLLATE: %s", t) |
| 549 | } |
| 550 | |
| 551 | // NewTypeIsNotCompositeError generates an error suitable to report |
| 552 | // when a ColumnAccessExpr or TupleStar is applied to a non-composite |
nothing calls this directly
no test coverage detected