COMP3311 Final Exam 21T3 The University of New South Wales
COMP3311 Database Systems
Final Exam 21T3
Database Systems
[Front Page] [Notes] [Database] [Course Website] [Cheat Sheets]
[Q1] [Q2] [Q3] [Q4] [Q5] [Q6] [Q7] [Q8] [Q9] [Q10]

Question 4 (6 marks)

Write a PLpgSQL function that takes a property ID and returns the full address of that property.

create or replace function address(propID integer) returns text

Addresses are formatted as follows:

If the supplied ID does not exist in the database, return "No such property".

Examples of how the function works:

property=# select address(12345);
     address      
------------------
 No such property
(1 row)

property=# select address(46600);
                  address                  
-------------------------------------------
 9/153 Mill Hill Road, Bondi Junction 2022
(1 row)

property=# select address(46601);
              address               
------------------------------------
 10 Maitland Avenue, Kingsford 2032
(1 row)

property=# select id,ptype,address(id) from Properties order by id limit 5;
  id   |   ptype   |                address                 
-------+-----------+----------------------------------------
 45678 | House     | 10 Moira Crescent, Coogee 2034
 45679 | Apartment | 16/97 Paul Street, Bondi Junction 2022
 45680 | House     | 66 Jellicoe Avenue, Kingsford 2032
 45681 | Apartment | 11/41 Raleigh Street, Coogee 2034
 45682 | House     | 94 Burrows Road, Alexandria 2015
(5 rows)

More examples are in the tests directory.

Instructions:

End of Question