diff --git a/pgtype/numeric_test.go b/pgtype/numeric_test.go index 4852f442..f0591246 100644 --- a/pgtype/numeric_test.go +++ b/pgtype/numeric_test.go @@ -213,6 +213,12 @@ func TestNumericMarshalJSON(t *testing.T) { {"123e-3"}, {"243723409723490243842378942378901237502734019231380123e23790"}, {"3409823409243892349028349023482934092340892390101e-14021"}, + {"-1.1"}, + {"-1.0231"}, + {"-10.0231"}, + {"-0.1"}, // failed with "invalid character '.' in numeric literal" + {"-0.01"}, // failed with "invalid character '-' after decimal point in numeric literal" + {"-0.001"}, // failed with "invalid character '-' after top-level value" } { var num pgtype.Numeric var pgJSON string diff --git a/query_test.go b/query_test.go index bf1a1fe8..bb6b1114 100644 --- a/query_test.go +++ b/query_test.go @@ -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()