There’s one small omission in this, particularly relating to footnote 1, that you don’t have to use pq.Array. As long as you don’t mind using a non-standard type, lib/pq has types like [StringArray[(https://pkg.go.dev/github.com/lib/pq#StringArray) which handles reading a postgres text[] column into a (wrapped) []string - so you wouldn’t necessarily need to use pq.Array when using pgx.
Similarly, there’s a pgtype package which can be used with either pgx or pq in database/sql mode to provide similar types. pgtype has many more types available.
There’s one small omission in this, particularly relating to footnote 1, that you don’t have to use
pq.Array
. As long as you don’t mind using a non-standard type,lib/pq
has types like [StringArray
[(https://pkg.go.dev/github.com/lib/pq#StringArray) which handles reading a postgrestext[]
column into a (wrapped)[]string
- so you wouldn’t necessarily need to usepq.Array
when usingpgx
.Similarly, there’s a
pgtype
package which can be used with eitherpgx
orpq
indatabase/sql
mode to provide similar types.pgtype
has many more types available.You should be checking the result of https://pkg.go.dev/database/sql#Rows.Err