diff --git a/rows.go b/rows.go index 5f4fb099..fe6969e8 100644 --- a/rows.go +++ b/rows.go @@ -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]) } } diff --git a/values_test.go b/values_test.go index f15457fa..5884e228 100644 --- a/values_test.go +++ b/values_test.go @@ -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()) + }) +}