
------------------------------------------------------------
-- scalar functions
------------------------------------------------------------

-- isOccupiedDuring(licensePlate, Timestamp, Timestamp) returns true,
-- when the vehicle identified by licensePlate is reserved during the
-- interval given by the two timestamps
-- Implementation Language: SQL

-- duration(IntervalT) returns the length of the interval in hours
-- between the two end points of the interval,
-- Hint: use the - (minus) operator for timestamps and the extract
-- operators for hours and days.
-- Implementation Language: SQL


------------------------------------------------------------
-- table functions
------------------------------------------------------------
-- define a table function that returns all the reservations
-- for a certain vehicle identified by its licenseplate
-- Implementation Language: SQL

-- timetable returns a time table for vehicle 'car'. Time table starts at
-- 'start' and longs for numHours hour
-- Hint: timetable uses a recursive query (see queries session):

-- test:
select * from timetable('194 SUA', '2017-08-16 00:00'::timestamp, 36) t;
-- Implementation Language: SQL




------------------------------------------------------------
-- stored procedures
------------------------------------------------------------
-- define a stored procedure that creates a new reservation
-- and inserts it into the reservation table. Before performing the
-- actual insertion, do the necessary checks (vehicle and member do exist,
-- vehicle is free at the specified interval, member does not have 
-- reservation at the specified interval, interval is not in the past, etc.).
-- Hint: You can use views that you have created earlier in the lab.
-- Implementation Language: PL/pgSQL
create function addReservation(licPlate varchar,
	                       memberName   varchar,
	                       anfang Timestamp,
			       ende Timestamp)
	returns integer 

