6.0.0-alpha14
7/3/25

[#10919] Postgresql 9.0 bytea output is hex and should be escape
Summary Postgresql 9.0 bytea output is hex and should be escape
Queue Horde Base
Queue Version Git master
Type Bug
State Resolved
Priority 1. Low
Owners slusarz (at) horde (dot) org
Requester alex (at) ksz (dot) ch
Created 01/12/2012 (4921 days ago)
Due
Updated 10/21/2013 (4273 days ago)
Assigned 10/21/2013 (4273 days ago)
Resolved 10/21/2013 (4273 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
10/21/2013 09:32:04 PM Michael Rubinsky Comment #4
State ⇒ Resolved
Reply to this comment
Turns out this error s due to the version of the libpg not being 
recent enough to work with the new 9.x default of returning bytea data 
as hex.

I.e, If you uppgrade pgsql to 9.x you MUST make sure you recompile or 
update pdo_pgsql with version libpg >= 9.2 (9.1.x was tested and is 
broken in this regard).
10/21/2013 05:56:34 PM Michael Rubinsky Comment #3
State ⇒ Assigned
Version ⇒ Git master
Reply to this comment
In PostgreSQL 9.xx bytea values have hex as default output, but horde
expects escape.
(http://www.postgresql.org/docs/9.0/static/release-9-0.html)
No.  We don't expect anything.  PDO handles result parsing.
This is not true, at least not in current code.
We have unit tests that test exactly this and they work fine.
With "ALTER DATABASE horde SET bytea_output = 'escape'; " you can
change the output postgresql uses.
No.  We don't care what the output is - that is for PDO to worry 
about.  The only thing we care about is how to insert data into the 
DB.  And as is clearly discussed from that above page:
Not true.  The database returns the data either as hex data, or 
escaped octal depending on the server's bytea_ouput setting. We expect 
the later. See Horde_Db_Adapter_Postgres_Column::binaryToString(). In 
Postgres 9.x, with bytea_output set to 'hex' (the default in Postgres 
9) the regexp will NOT match. PDO doesn't care what the value of this 
setting is, it returns it as -is.
The bytea type always accepts both formats on input, regardless of 
this setting.
Yes. It accepts the data for WRITING regardless of the setting, but it 
will presented back to client code differently depending on the 
setting. Using an ALTER database statement is one way to fix, but 
another is to provide "options: --bytea_output=escape" in the 
connection string.

02/02/2012 02:47:18 AM Michael Slusarz State ⇒ Not A Bug
 
01/27/2012 08:26:14 AM Michael Slusarz Comment #2
State ⇒ Feedback
Reply to this comment
In PostgreSQL 9.xx bytea values have hex as default output, but 
horde expects escape. 
(http://www.postgresql.org/docs/9.0/static/release-9-0.html)
No.  We don't expect anything.  PDO handles result parsing.

We have unit tests that test exactly this and they work fine.
With "ALTER DATABASE horde SET bytea_output = 'escape'; " you can 
change the output postgresql uses.
No.  We don't care what the output is - that is for PDO to worry 
about.  The only thing we care about is how to insert data into the 
DB.  And as is clearly discussed from that above page:

The bytea type always accepts both formats on input, regardless of 
this setting.

You are going to have to come up with a failing unit test to prove otherwise.
01/24/2012 03:12:50 PM Jan Schneider Assigned to Michael Slusarz
State ⇒ Assigned
 
01/12/2012 02:01:53 PM alex (at) ksz (dot) ch Comment #1
Priority ⇒ 1. Low
State ⇒ Unconfirmed
Patch ⇒ No
Milestone ⇒
Queue ⇒ Horde Base
Summary ⇒ Postgresql 9.0 bytea output is hex and should be escape
Type ⇒ Bug
Reply to this comment
In PostgreSQL 9.xx bytea values have hex as default output, but horde 
expects escape. 
(http://www.postgresql.org/docs/9.0/static/release-9-0.html)

With "ALTER DATABASE horde SET bytea_output = 'escape'; " you can 
change the output postgresql uses.

If this isn't done. all pref_values in horde_prefs are corrupted. I 
had the problem when updating horde groupware webmail edition from 
4.0.3 to 4.0.4 and 4.0.5.

If I got this correctly the following happened:

4.0.3 -> 4.0.4

horde changed from using plaintext values in pref_value to using 
binary values, without changing the type of pref_value (it had still 
the type text). This wasn't that big a problem. the values looked 
somehow weird, but it worked quite a while.

4.0.4 -> 4.0.5

pref_value was changed from type text to type binary, also converting 
all the values. This lead to corrupted values. The pref_value field 
had the correct information in it, but also a lot of completely 
useless information (mostly long sequences of the number 3, some other 
numbers mixed in from time to time. A single pref_value had more than 
1 million signs alltough only a name and an e-mail address were 
stored). This happened because postgresql sent the bytea values as hex 
instead of escape format.

Changing the bytea_output from hex to bytea solves the problem. So the 
following line should be in the update scripts and in the create 
database script for postgresql 9.0

ALTER DATABASE horde SET bytea_output = 'escape';

Saved Queries