Postgresql Loop Through Array Backwards R