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.

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 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.