jackc/pgx · error

lseg

Error message

lseg: %w

What it means

After reading the four float64 coordinates of a binary-encoded line segment, the plan verifies the 32-byte payload was fully consumed. This wrapper fires when pgio reports a length mismatch — the value is truncated or has extra bytes beyond the fixed lseg layout.

Solutions

  1. Verify the column type is lseg and the binary value wasn't corrupted
  2. Use text format for the column as a workaround
  3. Check custom binary encoding logic if the value was client-produced
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/lseg.go:161 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/6cb7adbe8b04855e. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/lseg.go:161

type scanPlanBinaryLsegToLsegScanner struct{}

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

	if src == nil {
		return scanner.ScanLseg(Lseg{})
	}

	r := pgio.NewReader(src)

	x1 := r.Uint64()
	y1 := r.Uint64()
	x2 := r.Uint64()
	y2 := r.Uint64()

	if err := r.Finish(); err != nil {
		return fmt.Errorf("lseg: %w", err)
	}

	return scanner.ScanLseg(Lseg{
		P: [2]Vec2{
			{math.Float64frombits(x1), math.Float64frombits(y1)},
			{math.Float64frombits(x2), math.Float64frombits(y2)},
		},
		Valid: true,
	})
}

type scanPlanTextAnyToLsegScanner struct{}

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

	if src == nil {
		return scanner.ScanLseg(Lseg{})

View on GitHub (pinned to ec1a0befd2)