Where is the option id of a select custom attribute saved?

I have a custom attribute select for the product entity.
Let’s call it my_custom_attribute.

If I save the product from the backend the value goes on the catalog_product_entity_int table, instead if I save the attribute programmatically, example:

$product->setData('my_custom_attribute', 1342);
$product->save();

It is saved in the catalog_product_entity_varchar table. The type value passed is integer.

Why?