jackc/pgx · error

is less than the minimum value for Uint64

Error message

%d is less than the minimum value for Uint64

What it means

Uint64.Scan (database/sql path) range guard: an int64 source is negative, which an unsigned uint64 cannot represent, so the scan is rejected.

Solutions

  1. Scan into a signed type (pgtype.Int8, sql.NullInt64)
  2. Fix data that wrongly contains negatives for an unsigned target
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/uint64.go:49 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/025338a249bd00b4. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/uint64.go:49

// Uint64Value implements the [Uint64Valuer] interface.
func (n Uint64) Uint64Value() (Uint64, error) {
	return n, nil
}

// Scan implements the [database/sql.Scanner] interface.
func (dst *Uint64) Scan(src any) error {
	if src == nil {
		*dst = Uint64{}
		return nil
	}

	var n uint64

	switch src := src.(type) {
	case int64:
		if src < 0 {
			return fmt.Errorf("%d is less than the minimum value for Uint64", src)
		}
		n = uint64(src)
	case string:
		un, err := strconv.ParseUint(src, 10, 64)
		if err != nil {
			return err
		}
		n = un
	default:
		return fmt.Errorf("cannot scan %T", src)
	}

	*dst = Uint64{Uint64: n, Valid: true}

	return nil
}

// Value implements the [database/sql/driver.Valuer] interface.

View on GitHub (pinned to ec1a0befd2)