|< < 44 > >|

Postgres Stored Procedures

A function can return a table

Example

Find all employees who work for the employee with id x_id, either directly or indirectly.
create function works_for(x_id int) returns setof Employee as $$ declare e Employee; begin for e in select * from Employee where boss_id = x_id loop return next e; return query select * from works_for(e.emp_id); end loop; end $$ language plpgsql;

|< < 44 > >|