Possibly.. Same 204pin module.. :-/
You will need t be more specific on exact model #'s to check on RAM, but a 2009 is likely a 2.66/2.6 speed and will use 1066 MHz PC3-8500 DDR3 SDRAM
A 2012 model is going to most likely have 1600 MHz PC3-12800 DDR3L SDRAM which is still a 204 pin DDR3 Module, so it will likely 'fit' but at best it would run at the lower clock speed.. The new 'L' Low Voltage RAM runs @ 1.35v, and the other at 1.5v.. I cannot say how that may work out for sure..
That being said, I DO hope someone more 'techy' will chime in here.. 😕