-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change in behaviour from 1.1.4 to 1.2.3 #344
Comments
Thank you for raising this issue! It can be divided into two parts:
To 1: I think this is kind of unintended regression. pg-1.2 added Hash to JSON serialization to
So the classic Hash form is no longer usable in combination with a To 2: |
Ahh. Thanks for clarifying this. We'll have a discussion about how best to handle the new behaviour - maybe we'll have to try submitting the bytea data in the text format and watch how it performs.
Oops, this shows my limited understanding of the postgres API. Although my reproduction script uses the async API incorrectly thanks to my ignorance, I've checked out production code and it's using it correctly. Issue (1) is the root of the issue we ran into. |
Rails has it's own mechanisms to work with binary data. You usually can assign the binary data directly to the attribute of type If you want to use class BinaryData < String
end
conn = PG.connect
conn.exec("CREATE TEMP TABLE test (flag bool, data bytea, i int)")
conn.type_map_for_results = PG::BasicTypeMapForResults.new(conn)
conn.type_map_for_queries = PG::BasicTypeMapForQueries.new(conn)
conn.type_map_for_queries[BinaryData] = PG::BinaryEncoder::Bytea.new
bd = BinaryData.new("ab\xff\0cd")
conn.exec_params("INSERT INTO test (data, i) VALUES ($1, $2)", [bd, 3])
res = conn.exec("SELECT * FROM test")
p res.to_a # => [{"flag"=>nil, "data"=>"ab\xFF\x00cd", "i"=>3}] The part starting from |
It has always been easy to register a binary encoder to PG::BasicTypeMapForQueries like so: class BinaryData < String; end tm[BinaryData] = PG::BinaryEncoder::Bytea.new However it might be more convenient to add a default class that can be used without registration. Related to ged#344
We recently attempted an upgrade from 1.14 to 1.2.3 and encountered a behaviour change that failed some of our test suite.
I assume it may be because we are doing something not recommended, but I thought I'd post it here in case it's a bug.
Here's a basic reproduction script:
output on 1.1.4
output on 1.2.3
Inserting with a null byte fails silently, and inserting with only ascii bytes results in the entire hash (
{format: 1, value: "Hello"}
) being serialized as raw bytes.I notice the docs for send_query_params say:
Given that, attempting to use binary format and a type map may not be the correct thing to do. However, it seems to work (contrary to the docs) < 1.2. If its the wrong approach, can you recommend an alternative way to use type maps while also using the binary format for some columns?
The text was updated successfully, but these errors were encountered: