Common SQL Errors

PostgreSQL Error - 22021 character_not_in_repertoire Error Explained

August 4, 2025

Raised when a character cannot be represented in the target encoding during text conversion.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is the character_not_in_repertoire error in PostgreSQL?

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.

Error Highlights

Typical Error Message

PostgreSQL Error 22021

Error Type

Encoding Error

Language

PostgreSQL

Symbol

character_not_in_repertoire

Error Code

22021

SQL State

Explanation

Table of Contents

What is the character_not_in_repertoire error in PostgreSQL?

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.

When does it occur?

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.

Why is it important to fix quickly?

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.

.

Common Causes

Mismatched client_encoding

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.

Database created in non-UTF8 encoding

Databases initialized with SQL_ASCII or LATIN1 cannot store full Unicode text.

Inserting or copying Unicode data therefore fails.

Copying between differently encoded databases

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.

Incorrect file encoding in COPY

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.

.

Related Errors

FAQs

How do I quickly see my current client and server encodings?

Run SHOW client_encoding; and SHOW server_encoding; in psql or any SQL editor such as Galaxy to display the values immediately.

Can I force PostgreSQL to ignore unrepresentable characters?

No, PostgreSQL will not silently discard data. You must convert or replace characters explicitly with convert_to() or external scripts.

Will changing client_encoding affect stored data?

Changing client_encoding only alters how data is sent and received during the current session. Existing rows on disk remain untouched.

How does Galaxy help prevent this error?

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.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo