ResolveAsType implements the Constant interface.
(ctx *SemaContext, typ *types.T)
| 513 | |
| 514 | // ResolveAsType implements the Constant interface. |
| 515 | func (expr *StrVal) ResolveAsType(ctx *SemaContext, typ *types.T) (Datum, error) { |
| 516 | if expr.scannedAsBytes { |
| 517 | // We're looking at typing a byte literal constant into some value type. |
| 518 | switch typ.Family() { |
| 519 | case types.BytesFamily: |
| 520 | expr.resBytes = DBytes(expr.s) |
| 521 | return &expr.resBytes, nil |
| 522 | case types.UuidFamily: |
| 523 | return ParseDUuidFromBytes([]byte(expr.s)) |
| 524 | case types.StringFamily: |
| 525 | expr.resString = DString(expr.s) |
| 526 | return &expr.resString, nil |
| 527 | } |
| 528 | return nil, errors.AssertionFailedf("attempt to type byte array literal to %T", typ) |
| 529 | } |
| 530 | |
| 531 | // Typing a string literal constant into some value type. |
| 532 | switch typ.Family() { |
| 533 | case types.StringFamily: |
| 534 | if typ.Oid() == oid.T_name { |
| 535 | expr.resString = DString(expr.s) |
| 536 | return NewDNameFromDString(&expr.resString), nil |
| 537 | } |
| 538 | expr.resString = DString(expr.s) |
| 539 | return &expr.resString, nil |
| 540 | case types.BytesFamily: |
| 541 | return ParseDByte(expr.s) |
| 542 | } |
| 543 | |
| 544 | datum, err := ParseAndRequireString(typ, expr.s, ctx) |
| 545 | return datum, err |
| 546 | } |
| 547 | |
| 548 | type constantFolderVisitor struct{} |
| 549 |
nothing calls this directly
no test coverage detected