diff --git a/pgtype/numeric.go b/pgtype/numeric.go index bf42d5569..e33597039 100644 --- a/pgtype/numeric.go +++ b/pgtype/numeric.go @@ -234,7 +234,12 @@ func (n Numeric) MarshalJSON() ([]byte, error) { return []byte("null"), nil } - if n.NaN { + switch { + case n.InfinityModifier == Infinity: + return []byte(`"infinity"`), nil + case n.InfinityModifier == NegativeInfinity: + return []byte(`"-infinity"`), nil + case n.NaN: return []byte(`"NaN"`), nil } diff --git a/pgtype/range_test.go b/pgtype/range_test.go index 2a0534134..99fe03e7c 100644 --- a/pgtype/range_test.go +++ b/pgtype/range_test.go @@ -318,14 +318,14 @@ func TestRangeNumericMarshalJSON(t *testing.T) { LowerType: Exclusive, UpperType: Exclusive, Valid: true, - }, result: `"(NaN,16)"`}, + }, result: `"(-infinity,16)"`}, {src: Range[Numeric]{ Lower: Numeric{Int: big.NewInt(-16), Valid: true}, Upper: Numeric{InfinityModifier: Infinity, NaN: true, Valid: true}, LowerType: Inclusive, UpperType: Exclusive, Valid: true, - }, result: `"[-16,NaN)"`}, + }, result: `"[-16,infinity)"`}, } for i, tt := range tests {