How to use transaction in a trigger ? It seems there is no possibility to control transaction within function
You cannot. You don't get to introduce a transaction boundary in the middle of a statement's execution. Not to mention what it would mean to have transaction boundaries for deferred triggers.