Thread: Problem inserting binary data in bytea column of UTF-8 database
Dear all,
I have a problem when trying to insert binary data in a bytea column of my database. If the binary data contains non-UTF-8 characters, the insert operation is rejected with a "ERROR: invalid byte sequence for encoding "UTF8"" result.CREATE DATABASE test WITH TEMPLATE = template0 ENCODING = 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8';
\connect test;
CREATE TABLE test (test bytea);
insert into test (test) values (E'\xC744'::bytea);
This script generates same error when executed directly on the postgresql server with "psql" command.
Hi Brice, On 03/07/18 05:28, Brice André wrote: > insert into test (test) values (E'\xC744'::bytea); I think double backslash needs to be used. See https://www.postgresql.org/docs/current/static/datatype-binary.html#id-1.5.7.12.9 Best, Alex
On Thursday, July 5, 2018, Alexey Bashtanov <bashtanov@imap.cc> wrote:
Hi Brice,
On 03/07/18 05:28, Brice André wrote:insert into test (test) values (E'\xC744'::bytea);
I think double backslash needs to be used.
See https://www.postgresql.org/docs/current/static/datatype-bina ry.html#id-1.5.7.12.9
Or lose the "E" marker to turn the escape string literal into an ordinary string literal.
David J.
Hello Alexey,
You are right!2018-07-05 15:48 GMT+02:00 Alexey Bashtanov <bashtanov@imap.cc>:
Hi Brice,
On 03/07/18 05:28, Brice André wrote:insert into test (test) values (E'\xC744'::bytea);
I think double backslash needs to be used.
See https://www.postgresql.org/doc s/current/static/datatype- bina ry.html#id-1.5.7.12.9
Best,
Alex