Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

bytea hex format does not encode/decode properly #527

Closed
mikehale opened this Issue · 3 comments

2 participants

@mikehale

When saving a string value in a bytea type field in postgres 9 using the default hex format the value is encoded as a string of bytes. For example:

DB.create_table(:test) do
  primary_key :id
  File        :secret, :null => false
end

class Test < Sequel::Model
end

Test.create(:secret => "secret")
=> #<Test @values={:id=>1, :secret=>"x736563726574"}>
Test.first.secret
=> "x736563726574"
Test.first.secret[1..-1].scan(/../).map{|e| e.hex }.pack("C*")
=> "secret"

If one changes the bytea_output behavior to escape (previous postgres default) as described here, and restarts the connection then the expected output is received.

Test.first.secret
=> "secret"
@mikehale mikehale referenced this issue in dylanegan/openid-store-sequel
Closed

Strangeness! #1

@jeremyevans
Owner

This isn't a bug in Sequel:

Your database is stored in DB...
irb(main):001:0> DB.create_table!(:tests) do
irb(main):002:1*   primary_key :id
irb(main):003:1>   File        :secret, :null => false
irb(main):004:1> end
=> nil
irb(main):005:0> 
irb(main):006:0* class Test < Sequel::Model
irb(main):007:1> end
=> nil
irb(main):008:0> 
irb(main):009:0* Test.create(:secret => "secret")
=> #<Test @values={:id=>1, :secret=>"secret"}>
irb(main):010:0> Test.first.secret
=> "secret"

A few things can cause your issue:

  • Connecting to a PostgreSQL 9 server using a PostgreSQL <9 client (upgrade your PostgreSQL client/libpq in that case).
  • Using postgres-pr as the underlying driver (switch to jeremyevans-postgres-pr in that case).
  • Using an older jdbc-postgres gem (upgrade to the current version in that case).

If none of those seem to apply to you, please post more details about your environment to better help diagnose which part of it is causing your problem.

@mikehale

It appears that I am using libpq5=8.4.9-0ubuntu0.10.04, so that sounds like the issue. Thanks for the help.

@jeremyevans
Owner

Closing as the problem should go away after upgrading libpq.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.