jackc/pgx · error

result format codes length

Error message

result format codes length %d does not match field count %d

What it means

The number of result format codes supplied for a statement does not match the number of result columns and is not 0 or 1 (which apply universally). This is an internal consistency check between Bind-time validation and RowDescription.

Solutions

  1. Verify the number of format codes matches the column count
  2. Use a single format code to apply to all columns
  3. Use zero format codes to use defaults
  4. Report as a bug if using the public API correctly
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgconn/pgconn.go:3074 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/3543c379497816c9. Report an issue: GitHub.

Appendix: source

Thrown at pgconn/pgconn.go:3074

			outputFields[i] = inputFields[i]
			outputFields[i].Format = pgtype.TextFormatCode
		}
	case len(resultFormats) == 1:
		// Single format code applies to all columns.
		format := resultFormats[0]
		for i := range inputFields {
			outputFields[i] = inputFields[i]
			outputFields[i].Format = format
		}
	case len(resultFormats) == len(inputFields):
		// One format code per column.
		for i := range inputFields {
			outputFields[i] = inputFields[i]
			outputFields[i].Format = resultFormats[i]
		}
	default:
		// This should not occur if Bind validation is correct, but handle gracefully
		return fmt.Errorf("result format codes length %d does not match field count %d", len(resultFormats), len(inputFields))
	}

	return nil
}

View on GitHub (pinned to ec1a0befd2)