Invalid byte sequence for encoding "UTF8" - Azure Database for PostgreSQL flexible server

Tomasz Krajewski 96 Reputation points
2021-07-21T09:56:09.703+00:00

On freshly new Azure Database for PostgreSQL flexible server, I created a database:

CREATE DATABASE test
    WITH 
    OWNER = "myuser"
    ENCODING = 'UTF8'
    CONNECTION LIMIT = -1;

I am trying to run the following query:

SET client_encoding = 'UTF8';

DROP TABLE IF EXISTS customers;

CREATE TABLE customers (
    customer_id bpchar NOT NULL,
    company_name character varying(40) NOT NULL,
    contact_name character varying(30),
    contact_title character varying(30),
    address character varying(60),
    city character varying(15),
    region character varying(15),
    postal_code character varying(10),
    country character varying(15),
    phone character varying(24),
    fax character varying(24)
);

INSERT INTO customers VALUES ('ANATR', 'Ana Trujillo Emparedados y helados', 'Ana Trujillo', 'Owner', 'Avda. de la Constitución 2222', 'México D.F.', NULL, '05021', 'Mexico', '(5) 555-4729', '(5) 555-3745');

I received the following error:

ERROR:  invalid byte sequence for encoding "UTF8": 0xf3 0x6e 0x20 0x32
SQL state: 22021

In my local host environment, there are no issues. What could be an issue?

Azure Database for PostgreSQL
0 comments No comments
{count} votes

Accepted answer
  1. Tomasz Krajewski 96 Reputation points
    2021-07-21T10:13:01.453+00:00

    Solution found.

    There is an option under Server Parameters in Azure Database for PostgreSQL flexible server:

    116751-image.png

    Inside there client_encoding was set to SQL_ASCII when it requires to be UTF8

    116735-image.png

    After that change query works and pgadmin shows accents correctly.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.