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

**Code:** `22021` · **Category:** PostgreSQL · **Seen on:** PostgreSQL

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

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/postgresql/invalid-byte-sequence-for-encoding-utf8)
