jackc/pgx · error

cannot scan into from range element

Error message

cannot scan into %v from range element: %w

What it means

The lower bound's element scan plan ran and failed; the range scanner wraps the underlying error together with the failing target so the caller can see which bound could not be decoded. The root cause is the element-level decode failure.

Solutions

  1. Inspect the wrapped error to identify the element decode failure
  2. Check that the range element values are valid for the target type
  3. Fix the target type or element data based on the underlying error
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/range_codec.go:283 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/52ffda222c576d7a. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/range_codec.go:283

	if err != nil {
		return err
	}

	if ubr.LowerType == Empty {
		return rangeScanner.SetBoundTypes(ubr.LowerType, ubr.UpperType)
	}

	lowerTarget, upperTarget := rangeScanner.ScanBounds()

	if ubr.LowerType == Inclusive || ubr.LowerType == Exclusive {
		lowerPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, lowerTarget)
		if lowerPlan == nil {
			return fmt.Errorf("cannot scan into %v from range element", lowerTarget)
		}

		err = lowerPlan.Scan(ubr.Lower, lowerTarget)
		if err != nil {
			return fmt.Errorf("cannot scan into %v from range element: %w", lowerTarget, err)
		}
	}

	if ubr.UpperType == Inclusive || ubr.UpperType == Exclusive {
		upperPlan := plan.m.PlanScan(plan.rc.ElementType.OID, BinaryFormatCode, upperTarget)
		if upperPlan == nil {
			return fmt.Errorf("cannot scan into %v from range element", upperTarget)
		}

		err = upperPlan.Scan(ubr.Upper, upperTarget)
		if err != nil {
			return fmt.Errorf("cannot scan into %v from range element: %w", upperTarget, err)
		}
	}

	return rangeScanner.SetBoundTypes(ubr.LowerType, ubr.UpperType)
}

View on GitHub (pinned to ec1a0befd2)