jackc/pgx · error

is less than the minimum value for Uint32

Error message

%d is less than the minimum value for Uint32

What it means

Uint32.Scan range guard: the incoming value is negative, which an unsigned uint32 cannot represent, so the scan is rejected before assignment.

Solutions

  1. Scan into a signed type (pgtype.Int8, sql.NullInt64) or fix negative data
  2. Validate that the source is expected to be non-negative
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/uint32.go:61 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/67419b1ec64d9267. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/uint32.go:61

	}

	var n int64

	switch src := src.(type) {
	case int64:
		n = src
	case string:
		un, err := strconv.ParseUint(src, 10, 32)
		if err != nil {
			return err
		}
		n = int64(un)
	default:
		return fmt.Errorf("cannot scan %T", src)
	}

	if n < 0 {
		return fmt.Errorf("%d is less than the minimum value for Uint32", n)
	}
	if n > math.MaxUint32 {
		return fmt.Errorf("%d is greater than maximum value for Uint32", n)
	}

	*dst = Uint32{Uint32: uint32(n), Valid: true}

	return nil
}

// Value implements the [database/sql/driver.Valuer] interface.
func (src Uint32) Value() (driver.Value, error) {
	if !src.Valid {
		return nil, nil
	}
	return int64(src.Uint32), nil
}

View on GitHub (pinned to ec1a0befd2)