The general consensus is that buying is better if you expect to hold the property for the long-term.

Even if you move elsewhere, it may make sense to continue owning your property and rent it out to save on transaction costs. Converting your principal place of residence into an investment property has tax implications.