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

Function GetTypmodFromNumericPrecisionAndScale

server/types/numeric.go:91–99  ·  view source on GitHub ↗

GetTypmodFromNumericPrecisionAndScale takes Numeric type precision and scale and returns the type modifier value.

(precision, scale int32)

Source from the content-addressed store, hash-verified

89
90// GetTypmodFromNumericPrecisionAndScale takes Numeric type precision and scale and returns the type modifier value.
91func GetTypmodFromNumericPrecisionAndScale(precision, scale int32) (int32, error) {
92 if precision < 1 || precision > 1000 {
93 return 0, errors.Errorf("NUMERIC precision %v must be between 1 and 1000", precision)
94 }
95 if scale < -1000 || scale > 1000 {
96 return 0, errors.Errorf("NUMERIC scale 20000 must be between -1000 and 1000")
97 }
98 return ((precision << 16) | scale) + 4, nil
99}
100
101// GetPrecisionAndScaleFromTypmod takes Numeric type modifier and returns precision and scale values.
102func GetPrecisionAndScaleFromTypmod(typmod int32) (int32, int32) {

Callers 1

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected