The Duchess of Cambridge formally opened a new Astroturf during her visit to the school, where she told students she spent some of her "happiest years".
In a speech she said:
"It is such a treat to be back here at St Andrew’s. I absolutely loved my time here; they were some of my happiest years, which makes it so incredibly special to be here today.
"In fact, I enjoyed it so much that when I had to leave, I told my mother that I was going to come back to be a teacher. While that didn’t quite happen, I was thrilled to have been asked back today on St Andrew's Day.
"It was while I was here at school that I realised my love of sport. Sport has been a huge part of my life, and I feel incredibly grateful for the opportunities I had to get outside and play in such wonderful open spaces - though sadly there was nothing quite as glamorous as this in my time."
More top news
The 1D star will go ahead with his scheduled performance as per the wishes of his late mother, Johannah Deakin, who passed away on Friday.
Michael Gove admitted he made "mistakes" in his bid for the Tory Party leadership, and Theresa May was right to drop him from her cabinet.
Four people have been killed and at least 12 injured after a cargo train carrying propane-butane derailed and exploded in Bulgaria.