Thread: transactions surrounding extension functions

transactions surrounding extension functions

From
Forest Wilkinson
Date:
According to the postgres 7 docs:

>By default, Postgres executes transactions in unchained mode (also 
>known as “autocommit” in other database systems). In other words, each 
>user statement is executed in its own transaction and a commit is 
>implicitly performed at the end of the statement (if execution was 
>successful, otherwise a rollback is done). 

Does this mean that when I call a function I wrote, which is composed of
several queries, each of those queries will be executed in its own
transaction?  Or, will the statement containing the function call be
executed in its own transaction, thereby including all the queries
composing my function in that same transaction?

This is important when I have a function that performs a SELECT...FOR
UPDATE, followed by an UPDATE to the selected rows.  If I call that
function without surrounding it with BEGIN and END, the former behavior
would be dangerous, while the latter behavior would be desirable.

Thanks,

Forest Wilkinson



Re: transactions surrounding extension functions

From
Peter Eisentraut
Date:
Forest Wilkinson writes:

> Does this mean that when I call a function I wrote, which is composed
> of several queries, each of those queries will be executed in its own
> transaction?

No

> Or, will the statement containing the function call be executed in its
> own transaction, thereby including all the queries composing my
> function in that same transaction?

Yes

-- 
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/