Skip to content

docs: explain scanning array_agg (and other PG arrays) into Go slices#2539

Merged
jackc merged 1 commit into
jackc:masterfrom
alliasgher:docs/1900-array-agg-slice
Apr 25, 2026
Merged

docs: explain scanning array_agg (and other PG arrays) into Go slices#2539
jackc merged 1 commit into
jackc:masterfrom
alliasgher:docs/1900-array-agg-slice

Conversation

@alliasgher

Copy link
Copy Markdown
Contributor

Description

Users hitting a query that uses array_agg (or any PG array-returning expression) and who try to scan its result into a Go slice often see scan error: can't scan into dest[0]: unable to assign to *[]int64 and assume the feature isn't supported. The two-step recipe from #1900 — scan the array scalar into a slice with QueryRow / slice-typed Scan, then compose slice fields into structs via CollectRows + RowToStructByName — is the canonical answer but isn't currently discoverable from the package docs.

This PR adds a short paragraph with both forms to the PostgreSQL Data Types section of doc.go so go doc pgx / pkg.go.dev surface the recipe. Docs-only change; no behavior impact.

Closes #1900

Users hitting a query that uses `array_agg` (or any PG array-returning
expression) and who try to scan its result into a struct field often see
"unable to assign to *[]int64" and assume the feature is missing. The
two-step recipe from jackc#1900 — scan the array scalar into a slice with
`QueryRow` / slice-typed `Scan`, and compose slice fields into structs
via `CollectRows` / `RowToStructByName` — is the canonical answer but
isn't currently discoverable from the package docs.

Add a short paragraph with both forms to the PostgreSQL Data Types
section of `doc.go` so `go doc pgx` / pkg.go.dev surface the recipe.

Closes jackc#1900

Signed-off-by: Ali <alliasgher123@gmail.com>
@jackc jackc merged commit 0b4a1ad into jackc:master Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Scanning from array_agg() into a golang array

2 participants