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

Function numericImplicit

server/cast/numeric.go:75–101  ·  view source on GitHub ↗

numericImplicit registers all implicit casts. This comprises only the source types.

(builtInCasts map[id.Cast]casts.Cast)

Source from the content-addressed store, hash-verified

73
74// numericImplicit registers all implicit casts. This comprises only the source types.
75func numericImplicit(builtInCasts map[id.Cast]casts.Cast) {
76 framework.MustAddImplicitTypeCast(builtInCasts, framework.TypeCast{
77 FromType: pgtypes.Numeric,
78 ToType: pgtypes.Float32,
79 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
80 d := val.(*apd.Decimal)
81 f, _ := d.Float64()
82 return float32(f), nil
83 },
84 })
85 framework.MustAddImplicitTypeCast(builtInCasts, framework.TypeCast{
86 FromType: pgtypes.Numeric,
87 ToType: pgtypes.Float64,
88 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
89 d := val.(*apd.Decimal)
90 f, _ := d.Float64()
91 return f, nil
92 },
93 })
94 framework.MustAddImplicitTypeCast(builtInCasts, framework.TypeCast{
95 FromType: pgtypes.Numeric,
96 ToType: pgtypes.Numeric,
97 Function: func(ctx *sql.Context, val any, _, targetType *pgtypes.DoltgresType) (any, error) {
98 return pgtypes.GetNumericValueWithTypmod(val.(*apd.Decimal), targetType.GetAttTypMod())
99 },
100 })
101}

Callers 1

initNumericFunction · 0.85

Calls 3

MustAddImplicitTypeCastFunction · 0.92
GetAttTypModMethod · 0.80
Float64Method · 0.65

Tested by

no test coverage detected