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

Function typeCheckConstant

pkg/sql/sem/tree/constant.go:61–89  ·  view source on GitHub ↗
(c Constant, ctx *SemaContext, desired *types.T)

Source from the content-addressed store, hash-verified

59}
60
61func typeCheckConstant(c Constant, ctx *SemaContext, desired *types.T) (ret TypedExpr, err error) {
62 avail := c.AvailableTypes()
63 if !desired.IsAmbiguous() {
64 for _, typ := range avail {
65 if desired.Equivalent(typ) {
66 return c.ResolveAsType(ctx, desired)
67 }
68 }
69 }
70
71 // If a numeric constant will be promoted to a DECIMAL because it was out
72 // of range of an INT, but an INT is desired, throw an error here so that
73 // the error message specifically mentions the overflow.
74 if desired.Family() == types.IntFamily {
75 if n, ok := c.(*NumVal); ok {
76 _, err := n.AsInt64()
77 switch err {
78 case errConstOutOfRange64:
79 return nil, err
80 case errConstNotInt:
81 default:
82 return nil, errors.NewAssertionErrorWithWrappedErrf(err, "unexpected error")
83 }
84 }
85 }
86
87 natural := avail[0]
88 return c.ResolveAsType(ctx, natural)
89}
90
91func naturalConstantType(c Constant) *types.T {
92 return c.AvailableTypes()[0]

Callers 2

TypeCheckMethod · 0.85
TypeCheckMethod · 0.85

Calls 6

IsAmbiguousMethod · 0.80
EquivalentMethod · 0.80
FamilyMethod · 0.80
AvailableTypesMethod · 0.65
ResolveAsTypeMethod · 0.65
AsInt64Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…