The motivation for this is not obvious.
Much of what you can do in a function returning a table can also
be done by a query (or view).
- setof account: Return type is a set of
rows compatible with the account table.
- acct account: Declare a variable that will
store a row of account
- for acct in ... loop ... end loop: Iterate
over a query, binding each row to acct.
- if ... then ... end if: If construct, as
in other languages.
- return next acct: Appends one account
row to the set of rows that will be returned.
- On exit: Return the accumulated set of rows
and return to caller.
- select * from rich_accounts() Using the
function in a query.