From ecd0624743daaa9e19ee8202fa9874ed957ea15b Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Sat, 10 Aug 2024 11:25:48 +0200 Subject: [PATCH] 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 #578 --- lib/pg/basic_type_registry.rb | 1 + spec/pg/basic_type_map_for_results_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/pg/basic_type_registry.rb b/lib/pg/basic_type_registry.rb index a3a164d3..4a6daaa7 100644 --- a/lib/pg/basic_type_registry.rb +++ b/lib/pg/basic_type_registry.rb @@ -278,6 +278,7 @@ def register_default_types register_type 0, 'inet', PG::TextEncoder::Inet, PG::TextDecoder::Inet alias_type 0, 'cidr', 'inet' + register_type 0, 'record', PG::TextEncoder::Record, PG::TextDecoder::Record register_type 1, 'int2', PG::BinaryEncoder::Int2, PG::BinaryDecoder::Integer diff --git a/spec/pg/basic_type_map_for_results_spec.rb b/spec/pg/basic_type_map_for_results_spec.rb index fc74ab03..1bdcfa8f 100644 --- a/spec/pg/basic_type_map_for_results_spec.rb +++ b/spec/pg/basic_type_map_for_results_spec.rb @@ -316,6 +316,16 @@ end end + it "should do anonymous record type conversions" do + [0].each do |format| + res = @conn.exec_params( "SELECT 6, ROW(123, 'str', true, null), 7 + ", [], format ) + expect( res.getvalue(0,0) ).to eq( 6 ) + expect( res.getvalue(0,1) ).to eq( ["123", "str", "t", nil] ) + expect( res.getvalue(0,2) ).to eq( 7 ) + end + end + it "should do inet type conversions" do [0].each do |format| vals = [