Correct way to insert into two tables (in TZUpdateS
Posted: 07.07.2010, 10:29
(postgres 8, zeos 7,D2009)
I've a m x n relation between table A and B, and for this I use a table AB that contains references to both.
Now, for a certain tuple in A, I need to add a relation to B, so I need to insert an item into B and AB.
So I do
insert into B (datafield1,datafield2) values (value1,value2) ;
insert into AB (AID,BID) values (selectedAID, currval('B_id_seq'))
where selected AID is the ID of the selected A tuple, and I use currval to retrieve the value of B.id
However I assume this is unsafe since inbetween the two inserts a parallel query could update currval also?
What is the advised way of doing that (within the constraints of designtime TZQuery insertsql statement ?
I've a m x n relation between table A and B, and for this I use a table AB that contains references to both.
Now, for a certain tuple in A, I need to add a relation to B, so I need to insert an item into B and AB.
So I do
insert into B (datafield1,datafield2) values (value1,value2) ;
insert into AB (AID,BID) values (selectedAID, currval('B_id_seq'))
where selected AID is the ID of the selected A tuple, and I use currval to retrieve the value of B.id
However I assume this is unsafe since inbetween the two inserts a parallel query could update currval also?
What is the advised way of doing that (within the constraints of designtime TZQuery insertsql statement ?