jackc/pgx · error

invalid format for Box

Error message

invalid format for Box

What it means

The text box parser could not split the input on the '),(' separator between the two points (or on ',' inside a point), so the string does not follow the '(x1,y1),(x2,y2)' shape even though its length passed the minimum check.

Solutions

  1. Correct the value to exactly '(x1,y1),(x2,y2)' with proper parentheses and commas
  2. Re-format the value from stored coordinates instead of hand-editing text
  3. Reject malformed geometric input before it reaches the scanner
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/box.go:189 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/af7af56bf4d5f146. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/box.go:189

}

type scanPlanTextAnyToBoxScanner struct{}

func (scanPlanTextAnyToBoxScanner) Scan(src []byte, dst any) error {
	scanner := (dst).(BoxScanner)

	if src == nil {
		return scanner.ScanBox(Box{})
	}

	if len(src) < 11 {
		return fmt.Errorf("invalid length for Box: %v", len(src))
	}

	// Expected format: (x1,y1),(x2,y2)
	sp1, sp2, found := strings.Cut(string(src[1:len(src)-1]), "),(")
	if !found {
		return fmt.Errorf("invalid format for Box")
	}

	sx1, sy1, found := strings.Cut(sp1, ",")
	if !found {
		return fmt.Errorf("invalid format for Box")
	}
	sx2, sy2, found := strings.Cut(sp2, ",")
	if !found {
		return fmt.Errorf("invalid format for Box")
	}

	x1, err := strconv.ParseFloat(sx1, 64)
	if err != nil {
		return err
	}
	y1, err := strconv.ParseFloat(sy1, 64)
	if err != nil {
		return err

View on GitHub (pinned to ec1a0befd2)