Plan scans even if destination is nil

fixes #810
pull/816/head
Jack Christensen 2020-08-21 18:34:52 -05:00
parent 997a16dbc5
commit 43ce317556
2 changed files with 34 additions and 4 deletions

View File

@ -204,10 +204,7 @@ func (rows *connRows) Scan(dest ...interface{}) error {
if rows.scanPlans == nil {
rows.scanPlans = make([]pgtype.ScanPlan, len(values))
for i, dst := range dest {
if dst == nil {
continue
}
for i := range dest {
rows.scanPlans[i] = ci.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
}
}

View File

@ -950,3 +950,36 @@ func TestRowDecodeBinary(t *testing.T) {
ensureConnValid(t, conn)
}
}
// https://github.com/jackc/pgx/issues/810
func TestRowsScanNilThenScanValue(t *testing.T) {
t.Parallel()
testWithAndWithoutPreferSimpleProtocol(t, func(t *testing.T, conn *pgx.Conn) {
sql := `select null as a, null as b
union
select 1, 2
order by a nulls first
`
rows, err := conn.Query(context.Background(), sql)
require.NoError(t, err)
require.True(t, rows.Next())
err = rows.Scan(nil, nil)
require.NoError(t, err)
require.True(t, rows.Next())
var a int
var b int
err = rows.Scan(&a, &b)
require.NoError(t, err)
require.EqualValues(t, 1, a)
require.EqualValues(t, 2, b)
rows.Close()
require.NoError(t, rows.Err())
})
}