I want to go from Vienna to Bratislava by train, with the OBB Rex service. Is it necessary, or recommended, to book in advance, or is it normal to just come before the train leaves and purchase a ticket?
There is a "Bratislava Ticket" for €16 that covers a return journey from Vienna to Bratislava on any train, plus local buses and trams in Bratislava. You can buy this at the station just before you get on the train. A seat reservation isn't necessary, and I'm not sure if it's even possible.
Travel inexpensively to Slovakia with the Bratislava-Ticket (known as Euregio Slovakia). The ticket can be used with all public urban transport trains.
On the printed first day of validity, the Bratislava-Ticket is also valid as a day ticket for public urban transport in Bratislava (until 01:00 a.m. of the following day, or on 1 January until 06:00 a.m. of the following day).
There may be alternative tickets you can get if you just want a single or don't need the local transport. I'm not sure if you need or can get reservations with these.