lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
8.86k stars 908 forks source link

Not possible to scan into `pq.Array(&[]pq.NullTime)` in `lib/pq@v1.10.7` #1110

Open Strum355 opened 1 year ago

Strum355 commented 1 year ago

With a column of type TIMESTAMPTZ aggregated into one row's return column of type TIMESTAMPTZ[] via array_agg, the following doesnt return an error but marks each pq.NullTime.Valid as false.

The stacktrace: image

The variables and code location: image

The stringified value yields: 2023-03-03 17:43:52.010562+00 (without single or double quotes). Given that its []byte and not time.Time, the assert fails.

type PackageRepoReference struct {
        ID            int
        Scheme        string
        Name          string
        Blocked       bool
        LastCheckedAt *time.Time
    }
    var ref PackageRepoReference
    var (
        versionStrings []string
        ids            []int64
        blocked        []bool
        lastCheckedAt  []pq.NullTime
    )
    err := s.Scan(
        &ref.ID,
        &ref.Scheme,
        &ref.Name,
        &ref.Blocked,
        &ref.LastCheckedAt,
        pq.Array(&ids),
        pq.Array(&versionStrings),
        pq.Array(&blocked),
        pq.Array(&lastCheckedAt),
    )