Why isn't fetch showing data from refcursor in Postgres?

236 Views Asked by At

Any idea why this doesn't display data, and how to fix that?

create or replace function test_refcursor(a refcursor) 
returns setof refcursor as
$$
begin
    open a for select from accounts;
    return next a;
end;
$$ language plpgsql;
begin;

Then to try to select data:

mydb=> begin;
mydb=> select test_refcursor('a');
 test_refcursor
----------------
 a
(1 row)
mydb=> fetch all from a;
--
(58 rows)

Last part doesn't display anything. Does it just not support dynamically type cursors like this?

1

There are 1 best solutions below

1
On BEST ANSWER

Last part doesn't display anything as you don't want anything. Try:

...
open a for select * from accounts;
...