This is just a stab in the dark, but can you check the type of this column? If it is a binary type you might need to change your postgresql config:
http://www.postgresql.org/docs/9.1/static/datatype-binary.html
Regards,
Aaron
This is a bug we've seen in the past, and thought was resolved. The bug resides either in postgresql-libpq, postgresql-simple, or persistent-postgresql. Can you let us know your: OS, version of Postgresql, and version of the libpq library?
Michael
Michael
AFAIK, this issue should be solved unless your PostgreSQL server is
ill-configured, see [1]. So it could be an issue with
postgresql-simple or postgresql-libpq, but only Leon is qualified to
say that =).
[1] https://github.com/yesodweb/yesod/issues/243#issuecomment-3709375
--
Felipe.
Well, that is the bytea escaping for "hello world". Last time this issue came up, the problem was that that the libpq library from PostgreSQL 8 was being used to interact with a PostgreSQL 9 database. So what version of libpq are you using?
Leon
Please help us keep the Heroku documentation up to date by sending a patch.
Well, my suggestion is to turn on statement logging in PostgreSQL, by setting log_min_duration_statement = 0 in your postgresql.conf (In debian and ubuntu this is located in /etc/postgresql/, in Redhat and CentOS this is located in /var/lib/pgsql) Then "service postgresql reload", insert a story, fetch a story, and then look in the postgresql logs for what the SQL statements look like.
I'm suspicious that something is getting converted from say, bytea to text, which doesn't really do what you want:
psql=> select 'hello world'::text;
text
-------------
hello world
(1 row)
psql=> select ('hello world'::text)::bytea;
bytea
--------------------------
\x68656c6c6f20776f726c64
(1 row)
psql=> select (('hello world'::text)::bytea)::text;
text
--------------------------
\x68656c6c6f20776f726c64
(1 row)
Best,
Leon
I just reproduced this. I have an Html field that used to work fine
but now gets written to the database in hex:
2012-02-25 15:41:02 PST LOG: duration: 2.100 ms statement: INSERT
INTO "post"("content","family","author","created")
VALUES('\x42617a2e',1,1,'2012-02-25 23:41:02.04804+00') RETURNING id
This happened while in the midst of migrating to the latest
Yesod/Persistent libraries. Unfortunately I don't have a complete
history of what libraries changed (lesson for next migration: use a
brand new virthualenv), but the differences in my .cabal from the last
known-good configuration are:
- , yesod >= 0.9 && < 0.10
- , yesod-core >= 0.9.3 && < 0.10
- , yesod-form >= 0.3.3 && < 0.4
+ , yesod >= 0.10 && < 0.11
+ , yesod-core >= 0.10 && < 0.11
+ , yesod-form >= 0.4 && < 0.5
...
- , persistent >= 0.6.2 && < 0.7
- , persistent-postgresql >= 0.6 && < 0.7
+ , persistent >= 0.8 && < 0.9
+ , persistent-postgresql >= 0.8 && < 0.9
persistent and yesod were both freshly installed from github.
Another user is seeing this issue. This time immediately after
upgrading persistent to the new version dependent on your driver. So
it seems that there is a solution lurking here that HDBC new about.
Thanks,
Greg Weber
--
Felipe.
Andrew: would it be possible to pull the code from Github and try
building with it?
Michael
[1] https://github.com/yesodweb/persistent/commit/2b16863171686dd680599d861ae37a84d0916820
What I would like is to have ByteString always be treated as Binary
ByteString by postgresql-simple. =)
Cheers,
--
Felipe.
Nope, it uses blobs. Html's definition was asking for SqlString,
though. That was the bug here.
Cheers,
--
Felipe.
Just so I'm understanding correctly, is it true that you can store a
blob in a column of type varchar? Or is Html being converted to
something other than ByteString before heading out to the database?
Because my Html field is, in fact, stored in a varchar column with the
latest Persistent.
Html still uses SqlString and still uses VARCHAR. However, it doesn't
try to convert itself to ByteString anymore, and instead uses Text.
The other way of fixing this bug was to change the format of the
column, but that wouldn't be backwards compatible AFAICT.
Cheers,
--
Felipe.