jackc/pgx · error
hstore pair : key cannot be NULL
Error message
hstore pair %d: key cannot be NULL
What it means
Binary hstore decoding guard: pair %d's key bytes were marked NULL by the length header. PostgreSQL's hstore never allows NULL keys, so this indicates a corrupt or maliciously crafted binary payload, not valid hstore data.
Solutions
- Treat as corrupted or maliciously crafted data
- Verify the hstore extension produced the value
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pgtype/hstore.go:208 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/ed3387da8ff2364d.
Report an issue: GitHub.
Appendix: source
Thrown at pgtype/hstore.go:208
// Each pair carries at minimum two int32 length headers (key, value). This bounds the
// up-front make() against a malicious server claiming a huge pair count in a small message.
pairCount := r.Count(8)
if err := r.Err(); err != nil {
return fmt.Errorf("hstore: %w", err)
}
hstore := make(Hstore, pairCount)
// one allocation for all *string, rather than one per string, just like text parsing
valueStrings := make([]string, pairCount)
for i := range pairCount {
keyBytes, keyNull := r.Value()
valueBytes, valueNull := r.Value()
if err := r.Err(); err != nil {
return fmt.Errorf("hstore pair %d: %w", i, err)
}
if keyNull {
return fmt.Errorf("hstore pair %d: key cannot be NULL", i)
}
key := string(keyBytes)
if valueNull {
hstore[key] = nil
} else {
valueStrings[i] = string(valueBytes)
hstore[key] = &valueStrings[i]
}
}
if err := r.Finish(); err != nil {
return fmt.Errorf("hstore: %w", err)
}
return scanner.ScanHstore(hstore)
}
type scanPlanTextAnyToHstoreScanner struct{}View on GitHub (pinned to ec1a0befd2)