jackc/pgx · error

unable to encode %#v into %s format for %s (OID %d): %w

Error message

unable to encode %#v into %s format for %s (OID %d): %w

What it means

Error "unable to encode %#v into %s format for %s (OID %d): %w" thrown in jackc/pgx.

Source

Thrown at pgtype/pgtype.go:1967

func newEncodeError(value any, m *Map, oid uint32, formatCode int16, err error) error {
	var format string
	switch formatCode {
	case TextFormatCode:
		format = "text"
	case BinaryFormatCode:
		format = "binary"
	default:
		format = fmt.Sprintf("unknown (%d)", formatCode)
	}

	var dataTypeName string
	if t, ok := m.TypeForOID(oid); ok {
		dataTypeName = t.Name
	} else {
		dataTypeName = "unknown type"
	}

	return fmt.Errorf("unable to encode %#v into %s format for %s (OID %d): %w", value, format, dataTypeName, oid, err)
}

// Encode appends the encoded bytes of value to buf. If value is the SQL value NULL then append nothing and return
// (nil, nil). The caller of Encode is responsible for writing the correct NULL value or the length of the data
// written.
func (m *Map) Encode(oid uint32, formatCode int16, value any, buf []byte) (newBuf []byte, err error) {
	if isNil, callNilDriverValuer := isNilDriverValuer(value); isNil {
		if callNilDriverValuer {
			newBuf, err = (&encodePlanDriverValuer{m: m, oid: oid, formatCode: formatCode}).Encode(value, buf)
			if err != nil {
				return nil, newEncodeError(value, m, oid, formatCode, err)
			}

			return newBuf, nil
		} else {
			return nil, nil
		}
	}

View on GitHub (pinned to ec1a0befd2)

When it happens

Trigger: Thrown at pgtype/pgtype.go:1967 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: /data/errors/b7ac61817efac943.json. Report an issue: GitHub.