Unlike stored procedures, which can explicitly start & commit transactions, stored functions can't contain "Statements that perform explicit or implicit commits or rollbacks". Documentation is pretty clear about that, it's getting a little vague, when it comes to explain, why it is prohibited, by merely stating that SQL "standard" doesn't require it & leaves it up to the vendor.
I wonder however, does atomicity of commands such as SELECT
or DO
, affect stored function, when it's called within their context?
In such case, commands contained within stored function, are treated as one transaction or each one is as separate transaction (like stored procedure, without START TRANSACTION
)?
The first one seems to be true, it would even explain why it's forbidden to commit transaction within function body, also in case if something goes awry, then every change can be rolled-back automatically by SELECT
or DO
, this way maintaining "all or nothing" approach, but still it's more implied, than official straight-forward answer, documentation should cover this matter but it doesn't.
[It's purely theoretical matter]