lpad is the func to make sure a month is always two digits as an example.


select 
concat( extract (year from  foo.timestamp)::text, 
lpad (extract (month from  foo.timestamp)::text, 2, '0') ) 

 as yearmonth, 
count(1) 
from foo
where 
group by yearmonth 
order by yearmonth  asc 
yearmonthcount
2020055208
2020068584
2020077780
2020085382
2020093635
2020102791
2020111284
2020122704
2021012416
2021021964
2021032554
2021042935
2021052909
202106160