Postgres Stored Procedures
A function can return a table
Example: Write a function that returns all accounts with
balances > 100
Solution 1: Loop to find qualifying rows
create function rich_accounts() returns setof account as $$
declare
acct account;
begin
for acct in
select *
from account
loop
if acct.balance > 100 then
return next acct;
end if;
end loop;
end
$$ language plpgsql;
...
select * from rich_accounts();
|