Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fafjJ-0001wX-Vf for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Jul 2018 11:13:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fafjG-0005Us-RJ for pgsql-bugs@arkaria.postgresql.org; Wed, 04 Jul 2018 11:13:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fafjG-0005Ul-LX for pgsql-bugs@lists.postgresql.org; Wed, 04 Jul 2018 11:13:46 +0000 Received: from ec2-54-154-62-225.eu-west-1.compute.amazonaws.com ([54.154.62.225] helo=WIN-D84BPDQUF5D) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fafjD-0008IJ-H5 for pgsql-bugs@lists.postgresql.org; Wed, 04 Jul 2018 11:13:46 +0000 Received: from GPDPC1 (212.56.100.243) by WIN-D84BPDQUF5D (Axigen) with (ECDHE-RSA-AES128-SHA256 encrypted) ESMTPSA id 22FB68; Wed, 4 Jul 2018 12:13:38 +0100 From: To: , References: <153070214603.13259.8727718773496971274@wrigleys.postgresql.org> In-Reply-To: <153070214603.13259.8727718773496971274@wrigleys.postgresql.org> Subject: RE: BUG #15261: Insert binary data in bytea rejected due to UTF-8 encoding errors Date: Wed, 4 Jul 2018 12:13:39 +0100 Message-ID: <349f01d41388$0f9af300$2ed0d900$@gpdnet.co.uk> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQJQ9PcntLjyzWUVYb3N64/VeLPuZKOFJcIA Content-Language: en-gb X-AxigenSpam-Level: 9 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >=20 > I have a database using UTF-8 encoding and, in which I have bytea = columns > where I store binary data. >=20 > I followed instructions in > https://www.postgresql.org/docs/9.6/static/datatype-binary.html to = encode > the binary data, but it is still rejected due to a "ERROR: invalid = byte sequence > for encoding "UTF8"" error. >=20 > I wrote a small script that reproduces the problem in a small = database. The > script can be simply copy-pasted in a psql session: >=20 > CREATE DATABASE test WITH TEMPLATE =3D template0 ENCODING =3D 'UTF8' > LC_COLLATE =3D 'en_US.UTF-8' LC_CTYPE =3D 'en_US.UTF-8'; \connect = test; > CREATE TABLE test (test bytea); insert into test (test) values > (E'\xC744'::bytea); >=20 You'll notice in the link you provided for your example that you need an = extra backslash ('\') for the escape format you are using. Regards, Gary.