jackc/pgx · error

hstore pair %d: key cannot be NULL

Error message

hstore pair %d: key cannot be NULL

What it means

Error "hstore pair %d: key cannot be NULL" thrown in jackc/pgx.

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)

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: /data/errors/ed3387da8ff2364d.json. Report an issue: GitHub.