I am new to plpgsql and trying the below scenario. It would be helpful if someone could help on this issue.