Invalid byte sequence for encoding & quot; UTF8 & quot;: 0xe99d2c, utf80xe99d2c

Source: Internet
Author: User
Tags psql postgresql client ssl connection

Invalid byte sequence for encoding "UTF8": 0xe99d2c, utf80xe99d2c


Query failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe99d2c


The reason is that the client character set does not match the character set of the inserted content. PostgreSQL does not perform Character Set conversion by default. If the database is a UTF8 character set, the Chinese Character Set of the terminal is generally set to GBK (check the LANG environment variable for confirmation ), therefore, this encoding is stored in the database without conversion, and the database is UTF8. PostgreSQL reports the following error if it finds that it is not UTF8 encoding.
To enable the automatic character set conversion function, you must inform the PostgreSQL client of the character set used. At this time, you can set the PostgreSQL client encoding to GBK, and pg will automatically perform Character Set conversion.

The following is an experiment:



1
[Root @ hostalonetest ~] # Psql-h 192.168.18.210-Upostgres beiigang
Psql. bin (9.3.5, server 9.1.14)
SSL connection (cipher: DHE-RSA-AES256-SHA, bits: 256)
Type "help" for help.


Beiigang = #


2
Beiigang = # \ l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
----------- + ---------- + ------------- + -----------------------
Beiigang | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
Postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |


3
Beiigang = # show server_encoding;
Server_encoding
-----------------
UTF8
(1 row)


4
Beiigang = # show client_encoding;
Client_encoding
-----------------
UTF8
(1 row)


5
Beiigang = # create table tb_tt (id int, ctnr varchar (60 ));
CREATE TABLE


6
Beiigang = # insert into tb_tt (id, ctnr) values (1, 'newline ');
ERROR: invalid byte sequence for encoding "UTF8": 0xd0c2


7
Beiigang = # \ encoding GBK


8
Beiigang = # show client_encoding;
Client_encoding
-----------------
GBK
(1 row)


9
Beiigang = # insert into tb_tt (id, ctnr) values (1, 'newline ');
INSERT 0 1


10
Beiigang = # select * from tb_tt;
Id | ctnr
---- + --------
1 | new website
(1 row)


11
Beiigang = # show client_encoding;
Client_encoding
-----------------
GBK
(1 row)


Beiigang = #
Beiigang = # reset client_encoding;
RESET
Beiigang = # show client_encoding;
Client_encoding
-----------------
UTF8
(1 row)


When writing code, you can specify the client character set encoding when creating a database link.

Refer:

Http://www.postgresql.org/docs/9.3/interactive/multibyte.html




-----------------

Please refer to the following source for reprinting:
Blog.csdn.net/beiigang




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.