Postgresql Plpgsql Loop Through Array Backwards R