Search code examples
postgresqlcursorpostgresql-9.4

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


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?


Solution

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

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