MCPcopy Create free account
hub / github.com/dolthub/doltgresql / typeCheckConstant

Function typeCheckConstant

postgres/parser/sem/tree/constant.go:81–111  ·  view source on GitHub ↗
(
	ctx context.Context, semaCtx *SemaContext, c Constant, desired *types.T,
)

Source from the content-addressed store, hash-verified

79}
80
81func typeCheckConstant(
82 ctx context.Context, semaCtx *SemaContext, c Constant, desired *types.T,
83) (ret TypedExpr, err error) {
84 avail := c.AvailableTypes()
85 if !desired.IsAmbiguous() {
86 for _, typ := range avail {
87 if desired.Equivalent(typ) {
88 return c.ResolveAsType(ctx, semaCtx, desired)
89 }
90 }
91 }
92
93 // If a numeric constant will be promoted to a DECIMAL because it was out
94 // of range of an INT, but an INT is desired, throw an error here so that
95 // the error message specifically mentions the overflow.
96 if desired.Family() == types.IntFamily {
97 if n, ok := c.(*NumVal); ok {
98 _, err := n.AsInt64()
99 switch {
100 case errors.Is(err, errConstOutOfRange64):
101 return nil, err
102 case errors.Is(err, errConstNotInt):
103 default:
104 return nil, errors.NewAssertionErrorWithWrappedErrf(err, "unexpected error")
105 }
106 }
107 }
108
109 natural := avail[0]
110 return c.ResolveAsType(ctx, semaCtx, natural)
111}
112
113func naturalConstantType(c Constant) *types.T {
114 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