jackc/pgx · error
invalid array, expected
Error message
invalid array, expected '[' or '=' got %v
What it means
Thrown while parsing the explicit-dimension prefix of a PostgreSQL text array literal (e.g. '[1:2]={...}') in parseUntypedTextArray. After the opening '[', the parser loops expecting either another '[' starting a dimension or '=' introducing the value body; any other rune (typo, missing '=', stray space) fails here.
Solutions
- Fix the array literal so each dimension reads '[lower:upper]' and the prefix ends with '=' before the '{' body
- Drop the explicit-dimension prefix and pass the bare '{...}' literal, letting pgx infer dimensions
- If the value comes from user input, validate/escape it before sending it as a text array
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/array.go:129 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: /api/errors/049a037bbcc03338.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/array.go:129
return nil, fmt.Errorf("invalid array: %w", err)
}
var explicitDimensions []ArrayDimension
// Array has explicit dimensions
if r == '[' {
buf.UnreadRune()
for {
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %w", err)
}
if r == '=' {
break
} else if r != '[' {
return nil, fmt.Errorf("invalid array, expected '[' or '=' got %v", r)
}
lower, err := arrayParseInteger(buf)
if err != nil {
return nil, fmt.Errorf("invalid array: %w", err)
}
r, _, err = buf.ReadRune()
if err != nil {
return nil, fmt.Errorf("invalid array: %w", err)
}
if r != ':' {
return nil, fmt.Errorf("invalid array, expected ':' got %v", r)
}
upper, err := arrayParseInteger(buf)
if err != nil {View on GitHub (pinned to ec1a0befd2)