In a plpgsql function how can I return a query and return from the function itself? If I just do return query select ... the statement after gets executed as well, so the return doesn't actually return from the whole function?
Use just return; as a single statement, example:
create or replace function my_func()
returns setof int language plpgsql as $$
begin
return query select generate_series(1,2);
return;
return query select generate_series(3,4);
end $$;
select my_func();
my_func
---------
1
2
(2 rows)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With