Fix scan pointer to pointer to nil slice
https://github.com/jackc/pgx/issues/1263
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/anynil"
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
)
|
||||
|
||||
@@ -216,6 +217,12 @@ func (c *ArrayCodec) PlanScan(m *Map, oid uint32, format int16, target any) Scan
|
||||
return nil
|
||||
}
|
||||
|
||||
// target / arrayScanner might be a pointer to a nil. If it is create one so we can call ScanIndexType to plan the
|
||||
// scan of the elements.
|
||||
if anynil.Is(target) {
|
||||
arrayScanner = reflect.New(reflect.TypeOf(target).Elem()).Interface().(ArraySetter)
|
||||
}
|
||||
|
||||
elementType := arrayScanner.ScanIndexType()
|
||||
|
||||
elementScanPlan := m.PlanScan(c.ElementType.OID, format, elementType)
|
||||
|
||||
Reference in New Issue
Block a user