{"id":"114444d61b434088","repo":"jackc/pgx","slug":"postgresql-array-has-d-dimensions-but-slice-has","errorCode":null,"errorMessage":"PostgreSQL array has %d dimensions but slice has %d dimensions","messagePattern":"PostgreSQL array has (.+?) dimensions but slice has (.+?) dimensions","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pgtype/builtin_wrappers.go","lineNumber":870,"sourceCode":"\tcase 0:\n\t\t// Empty, but non-nil array\n\t\tslice := reflect.MakeSlice(sliceType, 0, 0)\n\t\ta.slice.Set(slice)\n\t\treturn nil\n\tcase 1:\n\t\telementCount := cardinality(dimensions)\n\t\tslice := reflect.MakeSlice(sliceType, elementCount, elementCount)\n\t\ta.slice.Set(slice)\n\t\treturn nil\n\tdefault:\n\t\tsliceDimensionCount := 1\n\t\tlowestSliceType := sliceType\n\t\tfor ; lowestSliceType.Elem().Kind() == reflect.Slice; lowestSliceType = lowestSliceType.Elem() {\n\t\t\tsliceDimensionCount++\n\t\t}\n\n\t\tif sliceDimensionCount != len(dimensions) {\n\t\t\treturn fmt.Errorf(\"PostgreSQL array has %d dimensions but slice has %d dimensions\", len(dimensions), sliceDimensionCount)\n\t\t}\n\n\t\telementCount := cardinality(dimensions)\n\t\tflatSlice := reflect.MakeSlice(lowestSliceType, elementCount, elementCount)\n\n\t\tmultiDimSlice := a.makeMultidimensionalSlice(sliceType, dimensions, flatSlice, 0)\n\t\ta.slice.Set(multiDimSlice)\n\n\t\t// Now that a.slice is a multi-dimensional slice with the underlying data pointed at flatSlice change a.slice to\n\t\t// flatSlice so ScanIndex only has to handle simple one dimensional slices.\n\t\ta.slice = flatSlice\n\n\t\treturn nil\n\t}\n}\n\nfunc (a *anyMultiDimSliceArray) makeMultidimensionalSlice(sliceType reflect.Type, dimensions []ArrayDimension, flatSlice reflect.Value, flatSliceIdx int) reflect.Value {\n\tif len(dimensions) == 1 {","sourceCodeStart":852,"sourceCodeEnd":888,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/pgtype/builtin_wrappers.go#L852-L888","documentation":"Error \"PostgreSQL array has %d dimensions but slice has %d dimensions\" thrown in jackc/pgx.","triggerScenarios":"Thrown at pgtype/builtin_wrappers.go:870 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","schemaVersion":2}