jackc/pgx · error
invalid tsvector format: invalid position number
Error message
invalid tsvector format: invalid position number %q
What it means
consumePosition found digits but strconv.ParseUint rejected them as a 16-bit unsigned number — the position is 0, >16383, or otherwise out of range. The offending token is quoted in the message.
Solutions
- Use positions in the valid 1-16383 range
- Clamp or drop out-of-range positions before scanning
- Fix upstream data producing invalid tsvector positions
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/tsvector.go:433 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/55503562bab94107.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/tsvector.go:433
return positions, nil
}
// consumePosition consumes a single position number with optional weight letter.
func (p *tsvectorParser) consumePosition() (TSVectorPosition, error) {
start := p.pos
for !p.atEnd() && p.peek() >= '0' && p.peek() <= '9' {
p.consume()
}
if p.pos == start {
return TSVectorPosition{}, fmt.Errorf("invalid tsvector format: expected position number")
}
num, err := strconv.ParseUint(p.str[start:p.pos], 10, 16)
if err != nil {
return TSVectorPosition{}, fmt.Errorf("invalid tsvector format: invalid position number %q", p.str[start:p.pos])
}
pos := TSVectorPosition{Position: uint16(num), Weight: TSVectorWeightD}
// Check for optional weight letter
if !p.atEnd() {
switch p.peek() {
case 'A', 'a':
pos.Weight = TSVectorWeightA
case 'B', 'b':
pos.Weight = TSVectorWeightB
case 'C', 'c':
pos.Weight = TSVectorWeightC
case 'D', 'd':
pos.Weight = TSVectorWeightD
default:
return pos, nil
}View on GitHub (pinned to ec1a0befd2)