2

I am new to pg cursor, I have a cursor here:

create function simplecur() returns refcursor as $$
declare 
    abc cursor for 
    select t.registrant, u.display_name from incident_info t, sys_user u
    where t.registrant != 10000000 and u.id = t.registrant
    group by t.registrant, u.display_name
    order by t.registrant ;
begin
    open abc;
    return abc;
end
$$language plpgsql;

I simply use

select simplecur()

it returns

abc

now, i want to know ,how could i get the result of my sql , when i use

fetch all from abc;

it show me like this:

ERROR:  cursor "abc" does not exist
diligent
  • 2,282
  • 8
  • 49
  • 64

1 Answers1

1

You need to have an open transaction when you're using the cursor variable:

begin;
  select simplecur();
  fetch all in abc;
commit;

Another SO example.

Community
  • 1
  • 1
user272735
  • 10,473
  • 9
  • 65
  • 96