This error occurs when PostgreSQL cannot convert a character from the client encoding to the database encoding. Fix it by aligning encodings to UTF-8 or preprocessing data before import.
The "Untranslatable character" error (code 22P05) happens when PostgreSQL attempts to convert data from your client connection's encoding to the database's encoding and encounters a character that has no equivalent in the target encoding. For example, trying to insert a UTF-8 character like an em-dash (—) into a database using LATIN1 encoding will fail because LATIN1 cannot represent that character. PostgreSQL is strict about character encoding to maintain data integrity and prevent corruption.
Connect to your PostgreSQL database and check both the server and client encodings:
SHOW server_encoding;
SHOW client_encoding;If they differ, this may be causing the problem. The server encoding is set at database creation time and cannot be changed without recreation. The client encoding can be changed per-session.
Change your client encoding to match a universal encoding like UTF-8, which supports a wide range of characters:
SET client_encoding TO 'UTF8';For application connections, set this in your connection string. For psql, use the -E UTF-8 flag or set your terminal encoding.
Before importing files, validate their encoding using command-line tools:
file -I myfile.csv # Check file encoding
iconv -f UTF-8 -t LATIN1 myfile.csv # Test conversionIf conversion fails or produces errors, the file contains characters that cannot be represented in LATIN1. Use iconv to clean the file:
iconv -f UTF-8 -t LATIN1 -c myfile.csv > cleaned_file.csvThe -c flag omits characters that cannot be converted.
When using PostgreSQL's COPY command to import data, specify the file encoding explicitly:
COPY my_table FROM '/path/to/file.csv' WITH (FORMAT csv, ENCODING 'UTF8');This ensures PostgreSQL handles the conversion correctly.
For problematic columns, use PostgreSQL's convert_from() function to handle encoding conversion within SQL:
INSERT INTO my_table (name) VALUES (
convert_from('\xe28093'::bytea, 'UTF8')
);Alternatively, use convert_to() to inspect the byte representation of stored data:
SELECT convert_to(name, 'SQL_ASCII') FROM my_table;This helps diagnose encoding mismatches.
If you control database creation, always use UTF-8 encoding to avoid future encoding issues:
CREATE DATABASE mydb ENCODING 'UTF8' LOCALE 'C';UTF-8 supports the full Unicode character set and eliminates many character conversion problems.
PostgreSQL distinguishes between two character encoding errors: "character_not_in_repertoire" (22021) indicates corrupted bytes that cannot be decoded as valid characters in any encoding, while "untranslatable_character" (22P05) indicates a valid character that simply does not exist in the target encoding. If you have a legacy database using LATIN1 or WIN1252, be aware that converting to UTF-8 requires dumping and restoring the entire database — you cannot change the server encoding of an existing database. For systems with decomposed UTF-8 (where accented characters are stored as separate base + combining characters), there may be conversion issues to other encodings; in this case, consider normalizing to composed form first using the unaccent module. If using ODBC connections (e.g., Power BI), ensure your system DSN is configured for Unicode encoding, not ANSI.
insufficient columns in unique constraint for partition key
How to fix "insufficient columns in unique constraint for partition key" in PostgreSQL
ERROR 42501: must be owner of table
How to fix "must be owner of table" in PostgreSQL
trigger cannot change partition destination
How to fix "Trigger cannot change partition destination" in PostgreSQL
SSL error: certificate does not match host name
SSL error: certificate does not match host name in PostgreSQL
No SSL connection
No SSL connection to PostgreSQL