MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / ResolveAsType

Method ResolveAsType

pkg/sql/sem/tree/constant.go:515–546  ·  view source on GitHub ↗

ResolveAsType implements the Constant interface.

(ctx *SemaContext, typ *types.T)

Source from the content-addressed store, hash-verified

513
514// ResolveAsType implements the Constant interface.
515func (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
548type constantFolderVisitor struct{}
549

Callers

nothing calls this directly

Calls 8

DBytesTypeAlias · 0.85
ParseDUuidFromBytesFunction · 0.85
DStringTypeAlias · 0.85
NewDNameFromDStringFunction · 0.85
ParseDByteFunction · 0.85
ParseAndRequireStringFunction · 0.85
FamilyMethod · 0.80
OidMethod · 0.80

Tested by

no test coverage detected