jackc/pgx · error

unknown format code

Error message

unknown format code

What it means

Values() fallback guard: a column's OID has no registered type in the connection's type map and the field's format code is neither text (0) nor binary (1), so the raw bytes cannot even be guessed at. The unrecognized format code in the RowDescription is the faulty input — PostgreSQL itself only ever sends 0 or 1.

Solutions

  1. Check for a corrupted or non-PostgreSQL stream
  2. Verify custom proxy/protocol middleware isn't rewriting field format codes
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at rows.go:323 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/01d125a406391c1b. Report an issue: GitHub.

Appendix: source

Thrown at rows.go:323

			continue
		}

		if dt, ok := rows.typeMap.TypeForOID(fd.DataTypeOID); ok {
			value, err := dt.Codec.DecodeValue(rows.typeMap, fd.DataTypeOID, fd.Format, buf)
			if err != nil {
				rows.fatal(err)
			}
			values = append(values, value)
		} else {
			switch fd.Format {
			case TextFormatCode:
				values = append(values, string(buf))
			case BinaryFormatCode:
				newBuf := make([]byte, len(buf))
				copy(newBuf, buf)
				values = append(values, newBuf)
			default:
				rows.fatal(errors.New("unknown format code"))
			}
		}

		if rows.Err() != nil {
			return nil, rows.Err()
		}
	}

	return values, rows.Err()
}

func (rows *baseRows) RawValues() [][]byte {
	return rows.values
}

func (rows *baseRows) Conn() *Conn {
	return rows.conn
}

View on GitHub (pinned to ec1a0befd2)