From c46d792c932da071266cfe51e36bb27e2b29bfbb Mon Sep 17 00:00:00 2001 From: Mark Chambers Date: Wed, 4 Jan 2023 01:12:11 +0000 Subject: [PATCH] Numeric numberTextBytes() workaround... This seems a bit of a hack. It fixes the problems demonstrated in my previous commit. Maybe there's a cleaner way? Associated: https://github.com/jackc/pgx/issues/1426 --- pgtype/numeric.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pgtype/numeric.go b/pgtype/numeric.go index a5f4ed3a..9d51a7e5 100644 --- a/pgtype/numeric.go +++ b/pgtype/numeric.go @@ -243,7 +243,14 @@ func (n Numeric) MarshalJSON() ([]byte, error) { // numberString returns a string of the number. undefined if NaN, infinite, or NULL func (n Numeric) numberTextBytes() []byte { intStr := n.Int.String() + buf := &bytes.Buffer{} + + if len(intStr) > 0 && intStr[:1] == "-" { + intStr = intStr[1:] + buf.WriteByte('-') + } + exp := int(n.Exp) if exp > 0 { buf.WriteString(intStr)