pgtype.Numeric numberTextBytes() encoding bug
Demonstrate the problem with the tests:
...for negative decimal values e.g. -0.01
This causes errors when encoding to JSON:
"json: error calling MarshalJSON for type pgtype.Numeric"
It also causes scan failures of sql.NullFloat64:
"converting driver.Value type string ("0.-1") to a float64"
As reported here: https://github.com/jackc/pgx/issues/1426
This commit is contained in:
committed by
Jack Christensen
parent
74f9b9f0a4
commit
37c6f97b11
@@ -1219,6 +1219,34 @@ func TestConnQueryDatabaseSQLDriverValuerTextWhenBinaryIsPreferred(t *testing.T)
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
// https://github.com/jackc/pgx/issues/1426
|
||||
func TestConnQueryDatabaseSQLNullFloat64NegativeZeroPointZero(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
conn := mustConnectString(t, os.Getenv("PGX_TEST_DATABASE"))
|
||||
defer closeConn(t, conn)
|
||||
|
||||
type test struct {
|
||||
want sql.NullFloat64
|
||||
in float64
|
||||
}
|
||||
|
||||
tests := []float64{
|
||||
-0.01,
|
||||
-0.001,
|
||||
-0.0001,
|
||||
}
|
||||
|
||||
for _, val := range tests {
|
||||
var result sql.NullFloat64
|
||||
err := conn.QueryRow(context.Background(), "select $1::numeric", val).Scan(&result)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, sql.NullFloat64{Float64: val, Valid: true}, result)
|
||||
}
|
||||
|
||||
ensureConnValid(t, conn)
|
||||
}
|
||||
|
||||
func TestConnQueryDatabaseSQLNullX(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user