postgresqlbytea

Postgres and bytea columns appearing weird


I dumped a database and imported it into a different server. One of the tables has a bytea column and has a single row of data. On the original server, if I SELECT * FROM users;, it shows the correct value as @. - however, when I do that same select statement on the second server, I get \x402e for that same field. I have tried to wrap my head around this column type but it is over my head. Why would it appear as an escaped string on one server but not the other? Both servers are running Pg11 and I am accessing both via psql.

Original Server:

=# \d+ users
                                                         Table "public.users"
  Column   |          Type          | Collation | Nullable |              Default              | Storage  | Stats target | Description 
-----------+------------------------+-----------+----------+-----------------------------------+----------+--------------+-------------
 id        | integer                |           | not null | nextval('users_id_seq'::regclass) | plain    |              | 
 priority  | integer                |           | not null | 7                                 | plain    |              | 
 policy_id | integer                |           | not null | 1                                 | plain    |              | 
 email     | bytea                  |           | not null |                                   | extended |              | 
 fullname  | character varying(255) |           |          | NULL::character varying           | extended |              | 
=# SELECT * FROM users;
 id | priority | policy_id | email | fullname 
----+----------+-----------+-------+----------
  1 |        0 |         1 | @.    | 
(1 row)

Secondary Server:

=> \d+ users
                                                         Table "public.users"
  Column   |          Type          | Collation | Nullable |              Default              | Storage  | Stats target | Description 
-----------+------------------------+-----------+----------+-----------------------------------+----------+--------------+-------------
 id        | integer                |           | not null | nextval('users_id_seq'::regclass) | plain    |              | 
 priority  | integer                |           | not null | 7                                 | plain    |              | 
 policy_id | integer                |           | not null | 1                                 | plain    |              | 
 email     | bytea                  |           | not null |                                   | extended |              | 
 fullname  | character varying(255) |           |          | NULL::character varying           | extended |              | 
=> SELECT * FROM users;
 id | priority | policy_id | email  | fullname 
----+----------+-----------+--------+----------
  4 |        0 |         1 | \x402e | 
(1 row)

Solution

  • set bytea_output to hex; 
    select '@.'::bytea;
    
    ┌────────┐
    │ bytea  │
    ├────────┤
    │ \x402e │
    └────────┘
    
    set bytea_output to escape; 
    select '@.'::bytea;
    
    ┌───────┐
    │ bytea │
    ├───────┤
    │ @.    │
    └───────┘
    

    It seems that you have a different settings at your servers.

    Documentation