{"record":{"id":"cbda1317912d1d72","repo":"t8y2/dbx","slug":"failed-to-parse-constraint-s-referenced-columns","errorCode":null,"errorMessage":"failed to parse constraint %s referenced columns: %w","messagePattern":"failed to parse constraint (.+?) referenced columns: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/kingbase-go/kingbase_metadata.go","lineNumber":1878,"sourceCode":"\t\tdeferrable, initiallyDeferred bool\n\t\tvalid, enabled                bool\n\t}\n\traw := []rawConstraint{}\n\tfor rows.Next() {\n\t\tvar item rawConstraint\n\t\tvar columnsRaw, refColumnsRaw, validRaw, statusRaw any\n\t\tif err := rows.Scan(&item.name, &item.kind, &item.definition, &columnsRaw, &item.refSchema, &item.refTable, &refColumnsRaw, &item.matchType, &item.onUpdate, &item.onDelete, &item.deferrable, &item.initiallyDeferred, &validRaw, &statusRaw); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\titem.valid = parseConstraintEnabled(validRaw)\n\t\titem.enabled = parseConstraintEnabled(statusRaw)\n\t\titem.columns, err = parseCatalogAttributeNumbers(columnsRaw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse constraint %s columns: %w\", item.name, err)\n\t\t}\n\t\titem.refColumns, err = parseCatalogAttributeNumbers(refColumnsRaw)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse constraint %s referenced columns: %w\", item.name, err)\n\t\t}\n\t\traw = append(raw, item)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, err\n\t}\n\n\tattributes, err := s.relationAttributesByNumber(catalog, prefix, effective, table)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trefAttributes := map[string]map[int]string{}\n\tresult := make([]constraintInfo, 0, len(raw))\n\tfor _, item := range raw {\n\t\tconstraint := constraintInfo{\n\t\t\tName: item.name, ConstraintType: kingbaseConstraintTypeName(item.kind), Definition: item.definition,\n\t\t\tColumns: []string{}, RefColumns: []string{}, Deferrable: item.deferrable,\n\t\t\t// FK details are retained for API completeness and future unified","sourceCodeStart":1860,"sourceCodeEnd":1896,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/kingbase-go/kingbase_metadata.go#L1860-L1896","documentation":"The referenced-columns attribute of a constraint (e.g. a foreign key's refcolumns) could not be parsed into numeric column identifiers. The error names the constraint so the offending catalog row can be located.","triggerScenarios":"Listing constraints for a table whose foreign-key rows have a NULL/malformed refcolumns attribute, e.g. when a FK references a partitioned or dropped relation or the catalog stores an unexpected delimiter format.","commonSituations":"Kingbase version mismatches in FK catalog format; FKs pointing at tables in schemas the introspection query cannot resolve; corrupted system catalogs after failed migrations.","solutions":["Read the wrapped error to identify the malformed refcolumns value","Query the raw refcolumns attribute for the named constraint to inspect the format","Confirm driver and Kingbase server versions are compatible","Fix or drop/recreate the malformed foreign key constraint","Patch parseCatalogAttributeNumbers to tolerate the server's format"],"exampleFix":"// before\nrefCols, err := parseCatalogAttributeNumbers(refColumnsRaw)\n// after: skip/warn on non-numeric payloads instead of failing the whole listing\nrefCols, perr := parseCatalogAttributeNumbers(refColumnsRaw)\nif perr != nil {\n    log.Warnf(\"constraint %s refcolumns unparsable, skipping\", item.name)\n    refCols = nil\n}","handlingStrategy":"try-catch","validationCode":"// Go: verify FK refcolumns attribute is parseable before listing\nvar refCols sql.NullString\nerr := db.QueryRow(`SELECT confkey FROM pg_constraint WHERE conname=$1 AND contype='f'`, name).Scan(&refCols)\nif err != nil || !refCols.Valid || refCols.String == \"\" {\n    return fmt.Errorf(\"FK %s refcolumns attribute missing\", name)\n}","typeGuard":null,"tryCatchPattern":"conns, err := server.GetTableConstraints(ctx, schema, table)\nif err != nil {\n    if strings.Contains(err.Error(), \"referenced columns\") {\n        return fallbackRawConstraints(db, schema, table)\n    }\n    return err\n}","preventionTips":["Check FK health after schema migrations","Keep driver and Kingbase server versions compatible","Validate referenced relations still exist before introspection tooling runs"],"tags":["kingbase","metadata","foreign-key","catalog-parsing","go"],"backgroundTag":"catalog-attribute-parse-failed","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}