ResolveAsType implements the Constant interface.
( ctx context.Context, semaCtx *SemaContext, typ *types.T, )
| 602 | |
| 603 | // ResolveAsType implements the Constant interface. |
| 604 | func (expr *StrVal) ResolveAsType( |
| 605 | ctx context.Context, semaCtx *SemaContext, typ *types.T, |
| 606 | ) (TypedExpr, error) { |
| 607 | if expr.scannedAsBytes { |
| 608 | // We're looking at typing a byte literal constant into some value type. |
| 609 | switch typ.Family() { |
| 610 | case types.BytesFamily: |
| 611 | expr.resBytes = DBytes(expr.s) |
| 612 | return &expr.resBytes, nil |
| 613 | case types.EnumFamily: |
| 614 | e, err := MakeDEnumFromPhysicalRepresentation(typ, []byte(expr.s)) |
| 615 | if err != nil { |
| 616 | return nil, err |
| 617 | } |
| 618 | return NewDEnum(e), nil |
| 619 | case types.UuidFamily: |
| 620 | return ParseDUuidFromBytes([]byte(expr.s)) |
| 621 | case types.StringFamily: |
| 622 | expr.resString = DString(expr.s) |
| 623 | return &expr.resString, nil |
| 624 | } |
| 625 | return nil, errors.AssertionFailedf("attempt to type byte array literal to %s", typ.SQLStringForError()) |
| 626 | } |
| 627 | |
| 628 | // Typing a string literal constant into some value type. |
| 629 | switch typ.Family() { |
| 630 | // If we don't care about output type, just pick the low effort conversion. |
| 631 | case types.AnyFamily: |
| 632 | fallthrough |
| 633 | case types.StringFamily: |
| 634 | switch typ.Oid() { |
| 635 | case oid.T_name: |
| 636 | expr.resString = DString(expr.s) |
| 637 | return NewDNameFromDString(&expr.resString), nil |
| 638 | case oid.T_bpchar: |
| 639 | // TODO(mgartner): This should probably use the same logic in |
| 640 | // tree.AdjustValueToType and/or |
| 641 | // eval.performCastWithoutPrecisionTruncation. casts use (see the |
| 642 | // cast package). We might be able to replace this entire function |
| 643 | // with logic in those functions. |
| 644 | expr.resString = DString(strings.TrimRight(expr.s, " ")) |
| 645 | return &expr.resString, nil |
| 646 | default: |
| 647 | expr.resString = DString(expr.s) |
| 648 | return &expr.resString, nil |
| 649 | } |
| 650 | |
| 651 | case types.BytesFamily: |
| 652 | return ParseDByte(expr.s) |
| 653 | |
| 654 | default: |
| 655 | ptCtx := &simpleParseContext{ |
| 656 | // We can return any time, but not the zero value - it causes an error when |
| 657 | // parsing "yesterday". |
| 658 | RelativeParseTime: time.Date(2000, time.January, 2, 3, 4, 5, 0, time.UTC), |
| 659 | } |
| 660 | if semaCtx != nil { |
| 661 | ptCtx.DateStyle = semaCtx.DateStyle |
nothing calls this directly
no test coverage detected