| 1 | create function GetFlightCrew(
|
|---|
| 2 | FlightID_P int
|
|---|
| 3 | ) returns table (
|
|---|
| 4 | EmployeeId int,
|
|---|
| 5 | Name varchar(50),
|
|---|
| 6 | Surname varchar(50),
|
|---|
| 7 | DateOfBirth date,
|
|---|
| 8 | Role text
|
|---|
| 9 | ) as $$
|
|---|
| 10 | begin
|
|---|
| 11 | return query
|
|---|
| 12 | select employee.id, employee.name, employee.surname, employee.dateofbirth, 'Pilot'
|
|---|
| 13 | from pilot
|
|---|
| 14 | join employee on pilot.employeeid = employee.id
|
|---|
| 15 | join flight on flight.pilot = pilot.employeeid
|
|---|
| 16 | where flight.id = FlightID_P
|
|---|
| 17 |
|
|---|
| 18 | union all
|
|---|
| 19 |
|
|---|
| 20 | select employee.id, employee.name, employee.surname, employee.dateofbirth, 'Copilot'
|
|---|
| 21 | from pilot
|
|---|
| 22 | join employee on pilot.employeeid = employee.id
|
|---|
| 23 | join flight on flight.copilot = pilot.employeeid
|
|---|
| 24 | where flight.id = FlightID_P
|
|---|
| 25 |
|
|---|
| 26 | union all
|
|---|
| 27 |
|
|---|
| 28 | select employee.id, employee.name, employee.surname, employee.dateofbirth, 'Flight Attendant'
|
|---|
| 29 | from cabincrew
|
|---|
| 30 | join employee on cabincrew.flightattendantid = employee.id
|
|---|
| 31 | join flight on cabincrew.flightid = flight.id
|
|---|
| 32 | where flight.id = FlightID_P;
|
|---|
| 33 | end;
|
|---|
| 34 | $$ language plpgsql;
|
|---|