|< < 45 > >|

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.
insert into Employee(emp_id, boss_id, name) values (1, NULL, 'a'), (2, 1, 'b'), (3, 2, 'c'), (4, 2, 'd'), (5, 1, 'e'), (6, 1, 'f'), (7, 6, 'g'), (8, 6, 'h'), (9, 6, 'i'), (10, 7, 'j'); ... select * from works_for(6); emp_id | boss_id | name --------+---------+------ 7 | 6 | g 10 | 7 | j 8 | 6 | h 9 | 6 | i (4 rows)

|< < 45 > >|