22021 PostgreSQL Origin: Data Last updated 12 Oct 2026

ERROR: invalid byte sequence for encoding "UTF8": 0x00

Text contained bytes invalid in UTF-8 — often a NUL byte (0x00) or Latin-1/Windows-1252 data.

Exact message you may see invalid byte sequence for encoding "UTF8"
Seen on: PostgreSQL

Meaning

PostgreSQL text can’t contain \0. Imports from Excel/CSV in Windows encodings or binary data in text columns fail.

Common causes

  • NUL bytes in strings (from binary data or C strings)
  • CSV in Windows-1252/Latin-1 imported as UTF-8
  • Binary stored in text instead of bytea

⚡ Quick fix

  1. Strip \u0000 before inserting
  2. Convert files to UTF-8 (iconv)
  3. Use bytea for binary data
  4. COPY … WITH (ENCODING 'WIN1252')

Detailed fix by platform

Linux

  1. iconv -f WINDOWS-1252 -t UTF-8 export.csv > export-utf8.csv

How to diagnose

  1. Byte — Which byte? 0x00 = NUL
  2. Source — File encoding?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

1046 — MySQL ERROR 1046 (3D000): No database selected (MySQL)10461153 — MySQL ERROR 1153 (08S01): Got a packet bigger than 'max_allowed_packet' bytes (MySQL)1153declared and not used — Go: declared and not used: x / "fmt" imported and not used (Go)declared and not usednot a constructor — TypeError: x is not a constructor (JavaScript)not a constructorTDZ — ReferenceError: Cannot access 'x' before initialization (JavaScript)TDZTypeError: not a function — TypeError: x is not a function (JavaScript)TypeError: not a func…UnicodeDecodeError — UnicodeDecodeError: 'utf-8' codec can't decode byte 0x92 in position 10: invalid start byte (Python)UnicodeDecodeErrorUnicodeEncodeError — UnicodeEncodeError: 'charmap' codec can't encode character '\u2192' (Python)UnicodeEncodeError22021

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.