The seat Riker rejected would still be open. Some other Commander would take it and whoever wanted Riker's posting could get that opening (an XO spot on some other starship).
Yeah, you're right. Starfleet would go with its second choice, bizarre as that sounds.
Related to this, in the opposite direction, how are demotions in rank handled in the Navy? The one example from TNG that I can find is Crewman
Diana Giddings, who was an officer, then a crewman, though that could be the same oversight that happened with O'Brien. Voyager has Paris and Tuvok having been demoted, Paris in an episode where he also spent time in the brig, and for Tuvok, it may have just been oversight again, if I'm not mistaken.
Personnel can be demoted for disciplinary reasons, this is much more common for enlisted personnel. For officers a demotion is usually "on the side" as they are getting kicked out of the service.
Maybe a sidestep, but if I remember right Star Trek was based/presented on the idea of Hornblower in space.
So wouldn't it be better if we compare Starfleet to the Royal Navy during the early 19th century?
How was promotion and rank-holding handled at that time?
After all we cannot compare Starfleet to the current navy, where captains are in real-life contact with command and a new commanding officer and/or post is only a stone-throw away.
It's pretty much completely different. For one thing, there was no permanent service for officers; they weren't, say, Lieutenant So-and-so of the Royal Navy, they were Lieutenant So-and-so of His Majesty's Frigate
Nonsuch, and after that assignment was over they either found another ship or were unemployed with half their pay as retainer. There were almost no shore assignments. Every rate of ship had an authorized number of crew and officers. If there was an officer vacancy while overseas, a fleet commander could promote someone to fill it, but it wasn't guaranteed to be confirmed when they got home.
Except for a few petty officers, enlisted personnel were handled no higher that the ship level; the captain was responsible for "recruiting," rating and promoting them. They were simply discharged when their vessel went in for refit or into reserve. Discipline was severe.
There was only one job for commanders, which was to command a sloop, and there were more commanders than sloops so a lot of officers' careers stalled out at that grade. Once an officer became a captain, they would automatically advance to rear admiral, in order of seniority, as the higher ranks died or resigned (there was no retirement).
As far as being in contact with higher command, in TOS they seemed to be in touch with admirals fairly regularly. Not really like sailing vessels, when the fastest form of communication was mail on another ship.
TOS is essentially about a US Navy ship in space. The Hornblower comparison more applies to the characters themselves, especially Kirk.
Agreed 100%.