Yes. A candidate can choose an optional subject which he/she has not studied in his / her graduation or post-graduation. The UPSC provides a total of 26 optional subjects to choose from for the mains examination.
If you want to check proper educational qualification, click on the link provided.