jackc/pgx · error

unknown format code

Error message

unknown format code: %v

What it means

DecodeDatabaseSQLValue dispatches on the result format code, handling only the binary and text codes. This is the default-branch guard: it fires when the format code is neither of those two known values, which normally indicates a corrupt or nonstandard format code reached the decoder from the connection layer.

Solutions

  1. Report as a driver/protocol bug — PostgreSQL only defines text (0) and binary (1) format codes
  2. Verify no custom QueryResultFormats or middleware is injecting invalid format codes
  3. Upgrade pgx if a known format-code handling bug exists in your version
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/jsonb.go:101 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/61d6d7cd6e46c2e9. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/jsonb.go:101

	switch format {
	case BinaryFormatCode:
		if len(src) == 0 {
			return nil, fmt.Errorf("jsonb too short")
		}

		if src[0] != 1 {
			return nil, fmt.Errorf("unknown jsonb version number %d", src[0])
		}

		dstBuf := make([]byte, len(src)-1)
		copy(dstBuf, src[1:])
		return dstBuf, nil
	case TextFormatCode:
		dstBuf := make([]byte, len(src))
		copy(dstBuf, src)
		return dstBuf, nil
	default:
		return nil, fmt.Errorf("unknown format code: %v", format)
	}
}

func (c *JSONBCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (any, error) {
	if src == nil {
		return nil, nil
	}

	switch format {
	case BinaryFormatCode:
		if len(src) == 0 {
			return nil, fmt.Errorf("jsonb too short")
		}

		if src[0] != 1 {
			return nil, fmt.Errorf("unknown jsonb version number %d", src[0])
		}

View on GitHub (pinned to ec1a0befd2)