jackc/pgx · error
PostgreSQL array has %d dimensions but slice has %d dimensio
Error message
PostgreSQL array has %d dimensions but slice has %d dimensions
What it means
Error "PostgreSQL array has %d dimensions but slice has %d dimensions" thrown in jackc/pgx.
Source
Thrown at pgtype/builtin_wrappers.go:870
case 0:
// Empty, but non-nil array
slice := reflect.MakeSlice(sliceType, 0, 0)
a.slice.Set(slice)
return nil
case 1:
elementCount := cardinality(dimensions)
slice := reflect.MakeSlice(sliceType, elementCount, elementCount)
a.slice.Set(slice)
return nil
default:
sliceDimensionCount := 1
lowestSliceType := sliceType
for ; lowestSliceType.Elem().Kind() == reflect.Slice; lowestSliceType = lowestSliceType.Elem() {
sliceDimensionCount++
}
if sliceDimensionCount != len(dimensions) {
return fmt.Errorf("PostgreSQL array has %d dimensions but slice has %d dimensions", len(dimensions), sliceDimensionCount)
}
elementCount := cardinality(dimensions)
flatSlice := reflect.MakeSlice(lowestSliceType, elementCount, elementCount)
multiDimSlice := a.makeMultidimensionalSlice(sliceType, dimensions, flatSlice, 0)
a.slice.Set(multiDimSlice)
// Now that a.slice is a multi-dimensional slice with the underlying data pointed at flatSlice change a.slice to
// flatSlice so ScanIndex only has to handle simple one dimensional slices.
a.slice = flatSlice
return nil
}
}
func (a *anyMultiDimSliceArray) makeMultidimensionalSlice(sliceType reflect.Type, dimensions []ArrayDimension, flatSlice reflect.Value, flatSliceIdx int) reflect.Value {
if len(dimensions) == 1 {View on GitHub (pinned to ec1a0befd2)
When it happens
Trigger: Thrown at pgtype/builtin_wrappers.go:870 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04).
Data as JSON: /data/errors/114444d61b434088.json.
Report an issue: GitHub.