transactions in multiple action rules
Do the multiple actions within a multiple action rule implicitly reside
within a transaction? I notice that if I brace my multiple actions with
BEGIN; and COMMIT;, that I get a syntax error, so I'm assuming that's
because they are superfluous in that context... ?
(I want to be sure that I can count on 'currval' returning the sequence
value returned by the previous action's 'nextval', so that I know I am
inserting the proper foreign key into a table after inserting a record
into the referenced table.)
--
Ron Peterson
Network & Systems Manager
Mount Holyoke College
http://www.mtholyoke.edu/~rpeterso
On Mon, Dec 20, 2004 at 23:15:39 -0500,
Ron Peterson <rpeterso@mtholyoke.edu> wrote:
Do the multiple actions within a multiple action rule implicitly reside
within a transaction? I notice that if I brace my multiple actions with
BEGIN; and COMMIT;, that I get a syntax error, so I'm assuming that's
because they are superfluous in that context... ?(I want to be sure that I can count on 'currval' returning the sequence
value returned by the previous action's 'nextval', so that I know I am
inserting the proper foreign key into a table after inserting a record
into the referenced table.)
currval returns the last value given out by nextval in the same session.
So you don't need to worry about conflicts between sessions.
Ron Peterson <rpeterso@mtholyoke.edu> writes:
Do the multiple actions within a multiple action rule implicitly reside
within a transaction?
Yes. In the current code it is actually not possible for a single SQL
command issued by the client to give rise to more than one transaction.
(This might change if we invent some kind of stored-procedure engine, but
rules certainly can't do it.)
(I want to be sure that I can count on 'currval' returning the sequence
value returned by the previous action's 'nextval',
As Bruno pointed out, that really has nothing to do with how many
transactions are involved. The per-session state that currval uses will
sit quietly for as long as you need.
regards, tom lane