Skip to content

Commit 761b272

Browse files
committed
Add default decoder for anonymous record types to BasicTypeRegistry
The PostgreSQL server just sends the generic OID 2249 for generic record/composite types in query results like: SELECT row(123, 'str', true, null) Since we don't get the OIDs of the record items, we can not properly decode them. Nevertheless it's helpful to decode at least with the default type map and decode all items to an array of strings like so: c.exec("SELECT 6, row(123, 'str', true, null), 7").values => [[6, ["123", "str", "t", nil], 7]] instead of: => [[6, "(123,str,t,)", 7]] Related to ged#578
1 parent 0f387c0 commit 761b272

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/pg/basic_type_registry.rb

+1
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ def register_default_types
278278
register_type 0, 'inet', PG::TextEncoder::Inet, PG::TextDecoder::Inet
279279
alias_type 0, 'cidr', 'inet'
280280

281+
register_type 0, 'record', PG::TextEncoder::Record, PG::TextDecoder::Record
281282

282283

283284
register_type 1, 'int2', PG::BinaryEncoder::Int2, PG::BinaryDecoder::Integer

spec/pg/basic_type_map_for_results_spec.rb

+10
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,16 @@
316316
end
317317
end
318318

319+
[0].each do |format|
320+
it "should do format #{format} anonymous record type conversions" do
321+
res = @conn.exec_params( "SELECT 6, ROW(123, 'str', true, null), 7
322+
", [], format )
323+
expect( res.getvalue(0,0) ).to eq( 6 )
324+
expect( res.getvalue(0,1) ).to eq( ["123", "str", "t", nil] )
325+
expect( res.getvalue(0,2) ).to eq( 7 )
326+
end
327+
end
328+
319329
[0].each do |format|
320330
it "should do format #{format} inet type conversions" do
321331
vals = [

0 commit comments

Comments
 (0)