jackc/pgx · error

number of field descriptions must equal number of…

Error message

number of field descriptions must equal number of destinations, got %d and %d

What it means

baseRows.Scan received a number of destination arguments that differs from the row's column count — the dest slice length must exactly equal the number of FieldDescriptions. The two numbers in the message show the expected vs supplied counts.

Solutions

  1. Pass exactly one Scan destination per selected column
  2. Use an explicit SELECT column list that matches the Scan call
  3. Use generic helpers like RowToStructByPos or ForEachRow to avoid manual counting
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at rows.go:257 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/4b122cf43ec1b575. Report an issue: GitHub.

Appendix: source

Thrown at rows.go:257

	if len(fieldDescriptions) != len(values) {
		err := fmt.Errorf("number of field descriptions must equal number of values, got %d and %d", len(fieldDescriptions), len(values))
		rows.fatal(err)
		return err
	}

	if len(dest) == 1 {
		if rc, ok := dest[0].(RowScanner); ok {
			err := rc.ScanRow(rows)
			if err != nil {
				rows.fatal(err)
			}
			return err
		}
	}

	if len(fieldDescriptions) != len(dest) {
		err := fmt.Errorf("number of field descriptions must equal number of destinations, got %d and %d", len(fieldDescriptions), len(dest))
		rows.fatal(err)
		return err
	}

	if rows.scanPlans == nil {
		rows.scanPlans = make([]pgtype.ScanPlan, len(values))
		rows.scanTypes = make([]reflect.Type, len(values))
		for i := range dest {
			rows.scanPlans[i] = m.PlanScan(fieldDescriptions[i].DataTypeOID, fieldDescriptions[i].Format, dest[i])
			rows.scanTypes[i] = reflect.TypeOf(dest[i])
		}
	}

	for i, dst := range dest {
		if dst == nil {
			continue
		}

View on GitHub (pinned to ec1a0befd2)