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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.