jackc/pgx · error

convert field failed

Error message

convert field %d failed: %w

What it means

Wraps the per-column conversion failure in the stdlib driver's Rows.Next: the raw wire value for column %d could not be converted by its preselected valueFunc (bad binary encoding, invalid text syntax, etc.). The %w preserves the underlying cause for inspection.

Solutions

  1. Inspect the wrapped error to identify the column's root cause
  2. Cast the column in SQL or change the destination type for field i
  3. Investigate the stored data for encoding corruption
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at stdlib/sql.go:882 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/7bd0618cc05da000. Report an issue: GitHub.

Appendix: source

Thrown at stdlib/sql.go:882

		r.skipNext = false
	} else {
		more = r.rows.Next()
	}

	if !more {
		if r.rows.Err() == nil {
			return io.EOF
		} else {
			return r.rows.Err()
		}
	}

	for i, rv := range r.rows.RawValues() {
		if rv != nil {
			var err error
			dest[i], err = r.valueFuncs[i](rv)
			if err != nil {
				return fmt.Errorf("convert field %d failed: %w", i, err)
			}
		} else {
			dest[i] = nil
		}
	}

	return nil
}

func convertNamedArguments(args []any, argsV []driver.NamedValue) {
	for i, v := range argsV {
		if v.Value != nil {
			args[i] = v.Value.(any)
		} else {
			args[i] = nil
		}
	}
}

View on GitHub (pinned to ec1a0befd2)