Steven Moffat didn't tell any of the actors (except Alex Kingston and only very few of the crew) just who River Song is. David Tennant had no idea how to act opposite her, to great effect. On the DVD commentary, he says that he had The Doctor assume she's a future regeneration of him, because even though that made no sense, it made more sense than anything else he could come up with.
According to Steven Moffat, the squareness gun used by Professor River Song to help the party escape from the impending Vashta Nerada is intended to be the same sonic blaster that was used by Jack Harkness in the episode The Doctor Dances (2005). Moffat suggests that it was left in the TARDIS after The Parting of the Ways (2005), and taken by River Song in the Doctor's future. The name "squareness gun" was coined by Rose in the earlier episode.
The character of River Song was originally created for the plot to make more sense. Steven Moffat knew that the team of archaeologists would have to trust The Doctor, but that The Doctor's psychic paper could not explain and convince the team why he had appeared in a sealed-off library. Therefore, Moffat intended for The Doctor to know one of the archaeologists. Later, he decided that this idea was too "dull", and instead opted to have one of them know him.
Alex Kingston took the part of River Song under the assumption that the character would appear only in this two-parter. However, she was delighted to learn that Steven Moffat had longer-term plans for the character.
Steven Moffat stated that British newspaper The Sun got a hold of the script for the episode and threatened to publish it. Moffat jokingly told them to do it. He later remarked, "I'd like to see The Sun publish that many words in a day."