jackc/pgx · error

unknown boolean string representation

Error message

unknown boolean string representation %q

What it means

planTextToBool lowercases/trims the text and matches PostgreSQL's accepted boolean spellings (true/yes/on/1, false/no/off/0 and unique prefixes). Anything else — a misspelled or unrelated string — is rejected with the offending text quoted.

Solutions

  1. Use one of PostgreSQL's boolean representations: t/true/yes/on/1 or f/false/no/off/0
  2. Clean or normalize the source data before it is treated as a bool
  3. If the column is not boolean, fix the query/scan target mismatch
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pgtype/bool.go:344 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/7d884bde86211356. Report an issue: GitHub.

Appendix: source

Thrown at pgtype/bool.go:344

	v, err := planTextToBool(src)
	if err != nil {
		return err
	}

	return s.ScanBool(Bool{Bool: v, Valid: true})
}

// https://www.postgresql.org/docs/current/datatype-boolean.html
func planTextToBool(src []byte) (bool, error) {
	s := string(bytes.ToLower(bytes.TrimSpace(src)))

	switch {
	case strings.HasPrefix("true", s), strings.HasPrefix("yes", s), s == "on", s == "1": //nolint:gocritic // s is intentionally the prefix argument so partial inputs (t, tr, tru) also match.
		return true, nil
	case strings.HasPrefix("false", s), strings.HasPrefix("no", s), strings.HasPrefix("off", s), s == "0": //nolint:gocritic // s is intentionally the prefix argument so partial inputs (f, fa, fal) also match.
		return false, nil
	default:
		return false, fmt.Errorf("unknown boolean string representation %q", src)
	}
}

View on GitHub (pinned to ec1a0befd2)