This is a Jataka story.
The Wandering Ascetic
The future Buddha was sitting talking with the disciples when a wandering ascetic came to debate him. As the ascetic approached, the future Buddha asked: "Will you have a drink of Ganges water, fragrant with the scent of the forest?"
The ascetic replied: "What is the Ganges? Is the sand the Ganges? Is the water the Ganges? Is the hither bank the Ganges? Is the further bank the Ganges?"
But the future Buddha said to him: "If you take exception to the water, the sand, the hither bank, the further bank, where can you find any Ganges River?"
The wandering ascetic was confounded and rose up and went away. When he was gone, the future Buddha began teaching the assembly that was seated about. He spoke the following stanzas:
What he sees, he does not wish for,
But something that he does not see;
I think that he will wander long,
And what he wishes, not obtain.
He is not pleased with what he gets;
No sooner gained, it meets his scorn.
Insatiable are all wishes!
Those who are wish-free, therefore, we adore!