Postgresql Plpgsql Loop Through Array Backwards