Raised when a character cannot be represented in the target encoding during text conversion.
PostgreSQL Error 22021 (character_not_in_repertoire) appears when the server or client tries to store or transmit a character that the target encoding cannot represent. Align client and database encodings, or pre-convert the data with encode()/convert_to() to resolve the issue.
PostgreSQL Error 22021
PostgreSQL raises error code 22021 with condition name character_not_in_repertoire when it encounters a symbol that cannot be converted from one encoding to another.
The server aborts the statement instead of silently mangling the data, protecting text integrity.
The error frequently appears during INSERT, UPDATE, COPY, or client-server communication when the source string is UTF8 but the destination encoding is more limited, such as LATIN1 or SQL_ASCII.
The error fires as soon as PostgreSQL attempts to convert a string between client_encoding and server_encoding, between column encodings in a foreign table, or inside conversion functions like convert_to().
Any un-representable byte triggers an immediate failure.
Leaving the encoding mismatch unresolved blocks data ingestion pipelines, causes ETL jobs to fail, and may hide larger localization problems. Fixing it restores application uptime and ensures multilingual text is stored accurately.
.
If psql or an application connects with client_encoding=LATIN1 and sends UTF8 data, Unicode characters above codepoint 255 cannot be represented and trigger the error.
Databases initialized with SQL_ASCII or LATIN1 cannot store full Unicode text.
Inserting or copying Unicode data therefore fails.
Using dblink or foreign data wrappers to move text from a UTF8 source to a LATIN1 target will raise the error when the dataset contains unsupported characters.
COPY FROM reads a file using client_encoding. If the file is actually UTF8 yet the session encoding is LATIN1, non-Latin1 characters cause the error.
.
Run SHOW client_encoding; and SHOW server_encoding; in psql or any SQL editor such as Galaxy to display the values immediately.
No, PostgreSQL will not silently discard data. You must convert or replace characters explicitly with convert_to() or external scripts.
Changing client_encoding only alters how data is sent and received during the current session. Existing rows on disk remain untouched.
Galaxy automatically detects database and session encodings, warns on mismatches, and lets you set client_encoding in one click, reducing the odds of this error during query execution.