Re: Nested transaction - I am a bank ??
От | Richard Huxton |
---|---|
Тема | Re: Nested transaction - I am a bank ?? |
Дата | |
Msg-id | 200401131848.23299.dev@archonet.com обсуждение исходный текст |
Ответ на | Nested transaction - I am a bank ?? ("Thapliyal, Deepak" <dthapliyal@soe.sony.com>) |
Список | pgsql-general |
On Tuesday 13 January 2004 17:47, Thapliyal, Deepak wrote: > Hi, > > Assume I have a bank app.. When customer withdraws $10 from his accouint I > have to do following > --> update account_summary table [subtract $10 from his account] > --> update account detail_table [with other transaction details] > > Requirement: > either both transactions should succeed or both transactions should > be rolled back in case of failure. In database terms, the two operations together are one transaction. You do something like: BEGIN; INSERT INTO detail (acct_num,trans_type,trans_time,notes) VALUES (1,'CASHOUT',now(),'blah'); UPDATE account_summary SET amount=amount-10 WHERE acct_num = 1; COMMIT; Now, if one (or both) of those were written as a function, that function's effects would still be bound by the transaction. All operations(*) take place within a transaction in PG, either explicitly as above or implicitly with one per statement. What you can't do is have a function that does something like: LOOP 1..10 BEGIN; -- do something ten times, each time in its own transaction COMMIT; END LOOP (*) except for a couple of bits like vacuum, truncate(?) and similar. -- Richard Huxton Archonet Ltd
В списке pgsql-general по дате отправления: