Sadly, I can't assume the student name is unique, so I can't "join" on it.
Instead of assigning a unique identifier to student after inserting it into the table, assign the identifier first. Generally this is done by using “nextval()” explicitly in a manner similar to how it is used when computing the default for the serial column. Then you can return/join on the identifier reliably and not worry about duplicate student names.
David J.