Common SQL Errors

PostgreSQL error 22P05: untranslatable_character – causes and fixes

August 4, 2025

The server cannot translate a character in the incoming byte stream from client_encoding to the database’s internal encoding.

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 PostgreSQL error 22P05 untranslatable_character?

PostgreSQL error 22P05 (untranslatable_character) appears when the server cannot convert a character in the client input to the database’s encoding. Align client_encoding with the database encoding or cleanse the data with convert_to/convert_from to remove unsupported bytes to fix the problem.

Error Highlights

Typical Error Message

PostgreSQL Error 22P05

Error Type

Encoding Error

Language

PostgreSQL

Symbol

untranslatable_character

Error Code

22P05

SQL State

Explanation

Table of Contents

What is PostgreSQL error 22P05 (untranslatable_character)?

Error 22P05 is thrown when PostgreSQL attempts to convert data from the session’s client_encoding to the database’s server_encoding and encounters a byte sequence that has no mapping in the target set.

The failure aborts the current statement and any surrounding transaction. Fixing it is critical because partial loads, failed ETL jobs, and broken application writes lead to missing or corrupt data.

What Causes This Error?

Mismatched encodings trigger most 22P05 incidents. A psql session may default to UTF8 while the database was created with LATIN1, causing non-ASCII characters to stall COPY or INSERT commands.

Data imported from CSV, JSON, or external APIs can contain smart quotes, emojis, or multibyte glyphs that the target encoding does not support.

Locale misconfiguration on application servers also injects incompatible byte sequences, especially when Java, Node.js, or Python default to UTF-8 but connection pools announce SQL_ASCII.

How to Fix PostgreSQL Error 22P05

First, confirm encodings with SHOW client_encoding; and SHOW server_encoding;.

They must match or be mutually convertible (e.g., UTF8 to LATIN9).

If conversion is impossible, change the session encoding: SET client_encoding TO 'UTF8'; before running COPY or INSERT.

When data must stay in an older LATIN database, preprocess files through iconv or use PostgreSQL’s convert_from() and convert_to() to replace unsupported characters.

Galaxy flags encoding mismatches in the editor, suggesting the correct SET client_encoding statement before you run the query, reducing runtime failures.

.

Common Scenarios and Solutions

COPY FROM STDIN fails – Add the ENCODING clause: COPY tbl FROM 'file.csv' WITH (FORMAT csv, ENCODING 'UTF8');

Batch inserts via ORM – Ensure the connection string sets client_encoding=UTF8 or switch the driver to binary protocol.

psql restores – Use pg_dump --encoding=UTF8 and psql -v ON_ERROR_STOP=1 to halt on the first bad character.

Best Practices to Avoid This Error

Create new databases in UTF8 whenever possible. UTF8 supports the full Unicode range and avoids downstream translation issues.

Validate incoming files with file -I or iconv -f UTF8 -t LATIN1 before loading. Reject or cleanse bad rows early.

Automate SET client_encoding in application pools or use Galaxy’s connection templates, which inherit the database’s server_encoding and warn on drift.

Related Errors and Solutions

ERROR: 22021 invalid byte sequence for encoding – The server cannot even parse the byte sequence; sanitize the data or set the correct client_encoding.

ERROR: 42P17 invalid object definition – Appears when encoding issues corrupt DDL scripts; run with the proper psql locale.

ERROR: 57P03 cannot connect to the server – Not encoding-related but surfaces when misconfiguration blocks reconnection after 22P05 aborts.

Common Causes

Related Errors

FAQs

Does changing client_encoding affect stored data?

No. It only tells PostgreSQL how to interpret incoming and outgoing byte streams. The on-disk data remains in server_encoding.

Can I fix 22P05 without superuser rights?

Yes. Any user can issue SET client_encoding for their session or cleanse data with convert_from().

Should I always switch my database to UTF8?

UTF8 is safest for new databases. However, converting a legacy cluster may break applications expecting single-byte encodings. Test thoroughly.

How does Galaxy help avoid 22P05?

Galaxy auto-detects server_encoding during connection and warns you when pasted text contains characters the database cannot store.

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