2
0

Allow scanning null even if PG and Go types are incompatible

refs https://github.com/jackc/pgx/issues/1326
This commit is contained in:
Jack Christensen
2022-10-08 09:10:43 -05:00
parent 5655f9d593
commit af0b896290
2 changed files with 32 additions and 0 deletions
+15
View File
@@ -329,6 +329,21 @@ func TestMapScanPointerToRenamedType(t *testing.T) {
assert.Equal(t, "foo", string(*rs))
}
// https://github.com/jackc/pgx/issues/1326
func TestMapScanNullToWrongType(t *testing.T) {
m := pgtype.NewMap()
var n *int32
err := m.Scan(pgtype.TextOID, pgx.TextFormatCode, nil, &n)
assert.NoError(t, err)
assert.Nil(t, n)
var pn pgtype.Int4
err = m.Scan(pgtype.TextOID, pgx.TextFormatCode, nil, &pn)
assert.NoError(t, err)
assert.False(t, pn.Valid)
}
func BenchmarkMapScanInt4IntoBinaryDecoder(b *testing.B) {
m := pgtype.NewMap()
src := []byte{0, 0, 0, 42}