On Friday, November 9, 2012 9:51:24 AM UTC-7, Jeremy Evans wrote: > > > When storing data in a bytea column, you need to mark it as a blob: > > ds.insert(id: checkout_id, data: Sequel.blob(checkout_data)) > > That may fix your issue. >
Yep, that fixed my issue! I knew the Postgres function I needed to escape the binary data (i.e. escape_bytea), but I just couldn't find the Sequel method to access it. I looked at the code, but too many abstraction layers for me to follow. I'm guessing it is in the C code of the Postgres driver. Personally, I don't think serialization of ruby objects into a database is > a good idea in most cases, but if you have to do it with Marshal, it's > probably better to store it in bytea instead of base64 encoded text. > I am glad you offered your opinion Jeremy. You made me think about what I am trying to do. I do indeed want to serialize my objects because they are short-lived snapshots of a collection of objects. Doing so just makes life easier. However, I decided that they don't belong in the database. I decided that I can more easily manage these snapshots using files. I would also agree that it is better to store a Marshal.dump directly in a bytea column. For example, upon quick comparison of my snapshots, the binary data is about about 35% smaller than the base64 encoded text. > About your logger issue, use a custom logger that escapes the output > instead of the default Logger class, that's unrelated to Sequel. > Escaping the binary data using Sequel.blob fixed the garbling of my terminal. I am in fact using the standard Logger, so no need for a custom logger. The Postgres escape_bytea function must make the data terminal-friendly. -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/sequel-talk/-/x7C4DpXNLZAJ. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
