t8y2/dbx · error

failed to parse constraint %s referenced columns: %w

Error message

failed to parse constraint %s referenced columns: %w

What it means

Same as the constraint-columns parse failure but for the referenced (foreign-key) column list: parseVastbaseConstraintAttributeNumbers on confkey fails, wrapped as 'failed to parse constraint %s referenced columns'. Only foreign-key constraints carry confkey data, so this surfaces during FK introspection when that text is malformed.

Source

Thrown at agents/drivers/vastbase-go/vastbase_metadata.go:1589

		refSchema, refTable                           sql.NullString
		matchType, onUpdate, onDelete                 sql.NullString
		deferrable, initiallyDeferred, valid, enabled bool
	}
	raw := []rawConstraint{}
	for rows.Next() {
		var item rawConstraint
		var columnsRaw, refColumnsRaw sql.NullString
		var validRaw, enabledRaw any
		if 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, &enabledRaw); err != nil {
			return nil, err
		}
		item.columnNumbers, err = parseVastbaseConstraintAttributeNumbers(columnsRaw.String)
		if err != nil {
			return nil, fmt.Errorf("failed to parse constraint %s columns: %w", item.name, err)
		}
		item.refColumnNumbers, err = parseVastbaseConstraintAttributeNumbers(refColumnsRaw.String)
		if err != nil {
			return nil, fmt.Errorf("failed to parse constraint %s referenced columns: %w", item.name, err)
		}
		item.valid = parseVastbaseConstraintValid(validRaw)
		item.enabled = parseVastbaseConstraintEnabled(enabledRaw)
		raw = append(raw, item)
	}
	if err := rows.Err(); err != nil {
		return nil, err
	}

	attributes, err := s.relationAttributesByNumber(catalog, prefix, effective, table)
	if err != nil {
		return nil, err
	}
	refAttributes := map[string]map[int]string{}
	result := make([]constraintInfo, 0, len(raw))
	for _, item := range raw {
		constraint := constraintInfo{
			Name: item.name, ConstraintType: vastbaseConstraintTypeName(item.kind), Definition: item.definition,

View on GitHub (pinned to c0390bff16)

Solutions

  1. Inspect the named constraint's confkey value in the catalog to see the malformed text.
  2. Verify driver and server versions are compatible; update the driver for catalog format changes.
  3. Re-check/recreate the constraint if catalog data is genuinely corrupted.
  4. If empty confkey is legitimate for your server, patch/upgrade the driver to tolerate it.
Defensive patterns

Strategy: validation

Validate before calling

var confkey string
err := db.QueryRow(`SELECT confkey::text FROM pg_constraint WHERE conname=$1 AND contype='f'`, cname).Scan(&confkey)
if err == nil {
    for _, tok := range strings.FieldsFunc(confkey, func(r rune) bool { return r == ',' || r == ' ' || r == '\t' }) {
        if _, e := strconv.Atoi(tok); e != nil {
            return fmt.Errorf("malformed confkey %q for FK %s", confkey, cname)
        }
    }
}

Try / catch

fks, err := srv.ListForeignKeys(schema, table)
if err != nil && strings.Contains(err.Error(), "referenced columns") {
    // inspect confkey for the constraint named in the error
    return err
}

Prevention

When it happens

Trigger: Introspecting foreign key constraints when a constraint row's confkey text cannot be parsed into attribute numbers — empty string, NULL-ish rendering, or unexpected separators/characters.

Common situations: FK constraints against unusual server builds; driver/server catalog format mismatch; partially corrupted catalog metadata after failed migrations.

Understand the failure class

Related errors


AI-assisted analysis of t8y2/dbx@c0390bff16 (2026-09-05). Data as JSON: /api/errors/fd42708fd5b01cfd. Report an issue: GitHub.