jackc/pgx · error

invalid length for line

Error message

invalid length for line: %v

What it means

The textual line representation '{A,B,C}' needs at least 7 bytes including braces and two separating commas. This length guard fires before parsing when the source is shorter than that minimum, so the value cannot possibly be a well-formed line string.

Solutions

  1. Verify the stored value matches the '{a,b,c}' line text format
  2. Correct any custom encoding that produced the short string
  3. Use the binary format to avoid text parsing entirely
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/line.go:183 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/0d02290b3104a539. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/line.go:183

	return scanner.ScanLine(Line{
		A:     math.Float64frombits(a),
		B:     math.Float64frombits(b),
		C:     math.Float64frombits(c),
		Valid: true,
	})
}

type scanPlanTextAnyToLineScanner struct{}

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

	if src == nil {
		return scanner.ScanLine(Line{})
	}

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

	parts := strings.SplitN(string(src[1:len(src)-1]), ",", 3)
	if len(parts) < 3 {
		return fmt.Errorf("invalid format for line")
	}

	a, err := strconv.ParseFloat(parts[0], 64)
	if err != nil {
		return err
	}

	b, err := strconv.ParseFloat(parts[1], 64)
	if err != nil {
		return err
	}

	c, err := strconv.ParseFloat(parts[2], 64)

View on GitHub (pinned to ec1a0befd2)