在 postgresql-8 和 postgresql-12 中将字符串存储在 bytea 中的行为

behavior of storing string in bytea across postgresql-8 & postgresql-12

目前我正在将 postgres 数据库从 pg8 迁移到 pg12,但是我遇到了一个新问题

previously in pg8

 create table test (id int, data bytea);
 insert into test values (1,'hello world');
 table test;      

  id |    data
 ----+-------------
   1 | hello world
 (1 row)

Now in pg12

 create table test (id int, data bytea);
 insert into test values (1,'hello world');
 table test;

 id |           data
----+--------------------------
  1 | \x68656c6c6f20776f726c64
(1 row)

I want same behavior as pg8 as describe above. can anyone have an idea how should I achieve that.

and also why this behavior is different across different version? can anyone explain it.

需要在postgres.conf中设置才能转义bytea输出

 bytea_output = 'escape'

参见:https://www.postgresql.org/docs/14/datatype-binary.html