@@ -171,6 +171,25 @@ func TestNumericFloat64Valuer(t *testing.T) {
171171 assert .True (t , f .Valid )
172172}
173173
174+ func TestNumericInt64Valuer (t * testing.T ) {
175+ for i , tt := range []struct {
176+ n pgtype.Numeric
177+ i pgtype.Int8
178+ }{
179+ {mustParseNumeric (t , "1" ), pgtype.Int8 {Int64 : 1 , Valid : true }},
180+ {mustParseNumeric (t , "-99999999999" ), pgtype.Int8 {Int64 : - 99999999999 , Valid : true }},
181+ {mustParseNumeric (t , "0" ), pgtype.Int8 {Int64 : 0 , Valid : true }},
182+ // A valid Numeric with a nil Int is zero, matching Float64Value, Value,
183+ // and MarshalJSON. Int64Value used to dereference the nil Int and panic.
184+ {pgtype.Numeric {Valid : true }, pgtype.Int8 {Int64 : 0 , Valid : true }},
185+ {pgtype.Numeric {}, pgtype.Int8 {}},
186+ } {
187+ v , err := tt .n .Int64Value ()
188+ assert .NoErrorf (t , err , "%d" , i )
189+ assert .Equalf (t , tt .i , v , "%d" , i )
190+ }
191+ }
192+
174193func TestNumericCodecFuzz (t * testing.T ) {
175194 skipCockroachDB (t , "server formats numeric text format differently" )
176195
0 commit comments