U137: Invalid byte sequence for encoding

Category: Application / User Errors
SQLSTATE: 22021 (Class 22 - Data Exception: character_not_in_repertoire)
Urgency: low

Example Postgres Log Output:

ERROR: invalid byte sequence for encoding "UTF8": 0xd0 0x2e


This error occurs when you send text data, but either the source encoding doesn't match that currently set on the database, or the text stream contains binary data like NUL bytes that are not allowed within a string.

Recommended Action:

Its usually best to investigate the source data - is the data encoded with a different encoding than the one on the database? (e.g. latin1 on the client and UTF8 on the database).

You can override the client encoding thats assumed like this:

SET client_encoding = 'latin1'

Which will then convert the text data from the source encoding to the database encoding.

You can view the current server encoding like this:

postgres=# SHOW server_encoding;
(1 row)

In case the problem is that you are submitting binary data into a text field, it might make sense to consider using the bytea data type instead.

Learn More:

Download Free eBook: The Top 6 Postgres Log Events
Couldn't find what you were looking for or want to talk about something specific?
Start a conversation with us →