The Pinney equation and its discretization