How do I view the contents of a returns Postgresql cursor?
I have a custom function in Postgresql that returns a cursor. In Rails the returned values looks like an array that contains:
#<Order:0x007f6b63a49220> and #<Order:0x007f6b63a49040>
when I try to view the contents of these using .first or [0] I get an error
edit:
index.html.erb
<p><% @results %>
<p><% @results.each do |k,v| %>
<p><%= "key: #{k}" %></p>
<p><%= "value: #{v}" %></p>
<% end %></p>
test_controller.erb
@results = Order.retention_data(shop_id)
YYYYMMDD__add_process_functionstToDb.rb
class AddProcessFunctionstToDb < ActiveRecord::Migration
def up
funcs = File.read(Rails.root.join('db', 'migrate', 'processfunctions.sql').to_s)
execute funcs
end
def down
end
end
processfunctions.sql
drop function if exists retention_data(ref refcursor, shopId integer);
create or replace function retention_data(ref refcursor, shopId integer) returns refcursor as $$
begin
open ref for
...
close ref;
return ref;
end;
$$ language plpgsql;
edit2:
I tried
k.attribute_names
and it returned
"retention_data", "id"
they returned:
k.retention_data #> x (the name of the cursor)
k.id #> (nothing)
others:
@results.responds_to? #>undefined method `responds_to?' for #<ActiveRecord::Relation [#<Order id: nil>, #<Order id: nil>]>
puts k.inspect
andputs k.class