t8y2/dbx · error
invalid attribute number %q
Error message
invalid attribute number %q
What it means
Produced by parseCatalogAttributeNumbers when a token split out of a catalog attribute-number list (indkey, conkey, confkey) is not a valid integer. The helper expects the raw value to be a brace/bracket-delimited, comma/space separated list of integers like "1 2 3"; strconv.Atoi fails on anything else. It is always wrapped by callers ("failed to parse index/foreign key ... columns").
Source
Thrown at agents/drivers/kingbase-go/kingbase_metadata.go:1630
case nil:
return []int{}, nil
case string:
value = typed
case []byte:
value = string(typed)
default:
value = fmt.Sprint(typed)
}
value = strings.TrimSpace(strings.Trim(value, "{}[]"))
if value == "" {
return []int{}, nil
}
parts := strings.FieldsFunc(value, func(r rune) bool { return r == ',' || r == ' ' || r == '\t' })
result := make([]int, 0, len(parts))
for _, part := range parts {
number, err := strconv.Atoi(strings.TrimSpace(part))
if err != nil {
return nil, fmt.Errorf("invalid attribute number %q", part)
}
result = append(result, number)
}
return result, nil
}
func (s *server) relationAttributesByNumber(catalog, prefix, schema, table string) (map[int]string, error) {
query := fmt.Sprintf(`SELECT a.attnum, a.attname
FROM %s.%s_attribute a JOIN %s.%s_class c ON c.oid = a.attrelid
JOIN %s.%s_namespace n ON n.oid = c.relnamespace
WHERE n.nspname = %s AND c.relname = %s AND a.attnum > 0 AND NOT a.attisdropped`, catalog, prefix, catalog, prefix, catalog, prefix, quoteLiteral(schema), quoteLiteral(table))
rows, err := s.metadataQuery(query)
if err != nil {
return nil, err
}
defer rows.Close()
result := map[int]string{}
for rows.Next() {View on GitHub (pinned to c0390bff16)
Solutions
- Read the %q token in the message to see exactly which value is unparseable
- Run the underlying catalog query manually (SELECT indkey/conkey/confkey ...) to inspect the raw format the server returns
- Fix the data: drop/recreate the affected index or constraint so the catalog regenerates a numeric list
- Align driver/compat mode or upgrade the driver so the array type is scanned as a plain string of integers
Example fix
// before: bad catalog value "1 2 x" fails
nums, err := parseCatalogAttributeNumbers(raw) // invalid attribute number "x"
// after: repair the catalog entry
// find the constraint/index and recreate it: ALTER TABLE ... DROP CONSTRAINT fk_x; ALTER TABLE ... ADD CONSTRAINT fk_x FOREIGN KEY ... ;
nums, err := parseCatalogAttributeNumbers(raw) // []int{1,2} Defensive patterns
Strategy: validation
Validate before calling
// Go: validate the raw attribute list looks like integers before calling APIs that parse it
func looksLikeAttributeNumbers(raw any) bool {
var s string
switch v := raw.(type) {
case nil:
return true
case string:
s = v
case []byte:
s = string(v)
default:
s = fmt.Sprint(v)
}
for _, tok := range strings.FieldsFunc(strings.Trim(strings.TrimSpace(s), "{}[]"), func(r rune) bool { return r == ',' || r == ' ' || r == '\t' }) {
if _, err := strconv.Atoi(strings.TrimSpace(tok)); err != nil {
return false
}
}
return true
} Type guard
func isValidAttributeNumberList(raw any) bool {
s, ok := raw.(string)
if !ok {
b, isBytes := raw.([]byte)
if !isBytes { return raw == nil }
s = string(b)
}
s = strings.TrimSpace(strings.Trim(s, "{}[]"))
if s == "" { return true }
for _, tok := range strings.FieldsFunc(s, func(r rune) bool { return r == ',' || r == ' ' || r == '\t' }) {
if _, err := strconv.Atoi(tok); err != nil { return false }
}
return true
} Prevention
- Check conkey/confkey/indkey as text (cast to ::text) when debugging to see the exact server-side format
- Keep catalog data clean: recreate constraints/indexes instead of hand-editing system tables
- Test metadata queries against every Kingbase version you support, especially legacy V7
- If you control the scan, scan array columns as text so formatting surprises surface early
When it happens
Trigger: Any catalog metadata listing (indexes or foreign keys via listIndexesWithoutOrdinality / listForeignKeysFromCatalog) where the scanned conkey/confkey/indkey value, after trimming "{}[]", splits into tokens containing non-numeric characters — e.g. expression-index placeholders with unexpected values, corrupted catalog rows, or a driver delivering the array in an unexpected textual form.
Common situations: Connecting to a Kingbase version whose int2vector/int2[] text rendering differs (e.g. extra characters, quoted elements); a driver type-mapping change causing the array to arrive as a formatted structure whose fmt.Sprint output isn't a plain integer list; hand-edited or corrupted catalog data.
Related errors
- list custom types in schema %q: %w
- failed to parse index %s columns: %w
- failed to parse foreign key %s columns: %w
- failed to parse foreign key %s referenced columns: %w
- no usable HiveServer2 nodes in ZooKeeper namespace %s: %s
AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05).
Data as JSON: /api/errors/1cb93b28b1aa10e1.
Report an issue: GitHub.