A vertical beam subjected to compressive loads is called a column. In a properly-designed column, there will be no bending stresses unless a certain critical load is exceeded, at which point the column suddenly "pops" outward sideways, a condition called buckling. The critical buckling load depends on the slenderness of the column (its length relative to its cross-section) and the stiffness of the material from which it is made.
An analysis of column behavior including critical buckling loads for short versus slender columns, etc. is far too long to include here but will be found in any undergraduate mechanical engineering textbook dealing with strength of materials. Timoshenko & Gere is one example (probably out of print).