jackc/pgx · error

cannot scan NULL into *float32

Error message

cannot scan NULL into *float32

What it means

ScanInt64 was given a NULL Int8 while scanning into *float32, which cannot represent NULL. This is the null guard in float32Wrapper's conversion from int8; scan into a nullable type (e.g. *float32 wrapper via pgtype, or Float4) to accept NULLs.

Solutions

  1. Use COALESCE in the query to supply a default
  2. Scan into pgtype.Float4 or *float32 pointer to handle NULLs
  3. Ensure the queried column is NOT NULL
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/builtin_wrappers.go:315 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/811b02bdf6ab809f. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/builtin_wrappers.go:315

		return fmt.Errorf("cannot scan %v into *uint", ui)
	}

	*w = uintWrapper(ui)

	return nil
}

func (w uintWrapper) NumericValue() (Numeric, error) {
	return Numeric{Int: new(big.Int).SetUint64(uint64(w)), Valid: true}, nil
}

type float32Wrapper float32

func (w float32Wrapper) SkipUnderlyingTypePlan() {}

func (w *float32Wrapper) ScanInt64(v Int8) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *float32")
	}

	*w = float32Wrapper(v.Int64)

	return nil
}

func (w float32Wrapper) Int64Value() (Int8, error) {
	if w > math.MaxInt64 {
		return Int8{}, fmt.Errorf("%f is greater than maximum value for int64", w)
	}

	return Int8{Int64: int64(w), Valid: true}, nil
}

func (w *float32Wrapper) ScanFloat64(v Float8) error {
	if !v.Valid {
		return fmt.Errorf("cannot scan NULL into *float32")

View on GitHub (pinned to ec1a0befd2)