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

Question 5 (9 marks)

Write a PLpgSQL function that produces a list of groups and all of the music genres they have recorded albums in.

create type GroupGenres as ("group" text, genres text);

create or replace function q5() returns setof GroupGenres ...

The attributes in GroupGenres tuples are as follows:

The list of genres is produced as a single string and must be in alphabetical order of genres. If a group has never recorded ad album, return an empty string (not NULL).

Note that the function has no parameters, so will always produce the same result, e.g

music# select * from q5() order by "group";
        group         |                  genres                  
----------------------+------------------------------------------
 After the Sea        | hip-hop,post-rock,rock
 After the Sky        | 
 All of the Floyd     | rock
 All of the Sea       | hip-hop,pop,rock
 Black Eyed Boy       | country,hip-hop,rock
 Black Eyed Nails     | metal,pop,rock
 Black Mountains      | blues,rock
 Black Vanilla        | pop,rock
 Blue Floyd           | hip-hop,metal,pop,post-rock,rock
 Blue Mountains       | country,post-rock,rock
... etc etc etc ...

Warning: see the comments about ordering in the previous question.

Instructions:

End of Question