Thread: Nested transaction - I am a bank ??
Can I use a "set transaction" type mechanism within a function? thx Deep -----Original Message----- From: Joshua D. Drake [mailto:jd@commandprompt.com] Sent: Tuesday, January 13, 2004 10:17 AM To: Thapliyal, Deepak Cc: 'Richard Huxton'; Anton.Nikiforov@loteco.ru; pgsql-general@postgresql.org Subject: Re: [GENERAL] Nested transaction - I am a bank ?? 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. > >Question: > if my first update succeeds and second fails (say due to space errors >.. I have inconsistancy .. > > Not if you run the queries as a single transaction. >Per the thread below stored procedures/functions cannot have commits. I >assume that means that they will be implicitly commited ?? > >How do I approach this simple requirment using psql ? > >Thx >Deep > >-----Original Message----- >From: pgsql-general-owner@postgresql.org >[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Richard Huxton >Sent: Tuesday, January 13, 2004 4:32 AM >To: Anton.Nikiforov@loteco.ru >Cc: pgsql-general@postgresql.org >Subject: Re: [GENERAL] Parse error help needed... > > >On Tuesday 13 January 2004 12:01, Anton.Nikiforov@loteco.ru wrote: > > >>RH> Remove the "commit" line - functions cannot define their own >>transactions RH> anyway. >>Do you know if it will be solved sometime? Or this is architecture >>dependend problem? I mean that transactions are rulez and very helpful >>rulez when working with large databases. >> >> > >Nested transactions are on the todo list, but I don't know when they >will >appear. > > > -- Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC Postgresql support, programming shared hosting and dedicated hosting. +1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com Mammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL
No. You can set a transaction type with an explicit start transaction call before you call your function, but be aware that there are quirks within the pl framework ( like lack of query snapshot being refreshed) that might make things operate in a manner slightly different from normal transaction operations. Robert Treat On Tue, 2004-01-13 at 13:20, Thapliyal, Deepak wrote: > Can I use a "set transaction" type mechanism within a function? > > thx > Deep > > -----Original Message----- > From: Joshua D. Drake [mailto:jd@commandprompt.com] > Sent: Tuesday, January 13, 2004 10:17 AM > To: Thapliyal, Deepak > Cc: 'Richard Huxton'; Anton.Nikiforov@loteco.ru; > pgsql-general@postgresql.org > Subject: Re: [GENERAL] Nested transaction - I am a bank ?? > > > 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. > > > >Question: > > if my first update succeeds and second fails (say due to space > errors > >.. I have inconsistancy .. > > > > > > Not if you run the queries as a single transaction. > > > >Per the thread below stored procedures/functions cannot have commits. I > >assume that means that they will be implicitly commited ?? > > > >How do I approach this simple requirment using psql ? > > > >Thx > >Deep > > > >-----Original Message----- > >From: pgsql-general-owner@postgresql.org > >[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Richard Huxton > >Sent: Tuesday, January 13, 2004 4:32 AM > >To: Anton.Nikiforov@loteco.ru > >Cc: pgsql-general@postgresql.org > >Subject: Re: [GENERAL] Parse error help needed... > > > > > >On Tuesday 13 January 2004 12:01, Anton.Nikiforov@loteco.ru wrote: > > > > > >>RH> Remove the "commit" line - functions cannot define their own > >>transactions RH> anyway. > >>Do you know if it will be solved sometime? Or this is architecture > >>dependend problem? I mean that transactions are rulez and very helpful > >>rulez when working with large databases. > >> > >> > > > >Nested transactions are on the todo list, but I don't know when they > >will > >appear. > > > > > > > > > -- > Command Prompt, Inc., home of Mammoth PostgreSQL - S/ODBC and S/JDBC > Postgresql support, programming shared hosting and dedicated hosting. > +1-503-667-4564 - jd@commandprompt.com - http://www.commandprompt.com > Mammoth PostgreSQL Replicator. Integrated Replication for PostgreSQL > > ---------------------------(end of broadcast)--------------------------- > TIP 2: you can get off all lists at once with the unregister command > (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) -- Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL
On Tue, 13 Jan 2004, Thapliyal, Deepak wrote: > Thx Nigel.. > > Also can you kindly advice how to turn autocommit to off Probably: SET AUTOCOMMIT TO OFF; although I'm not sure that is still there in 7.4 and there was a lot of discussion on it's 'brokeness' I believe. I'm sure someone else will correct me if I'm wrong. I don't actually know as I've never used that feature, I have always used explicit transaction starts if I have wanted multistatement transactions, and I can't remember the details of the discussion now. A search of the list archives should yield a collection of posts on this subject. -- Nigel Andrews
On 14/01/2004 00:17 Nigel J. Andrews wrote: > > On Tue, 13 Jan 2004, Thapliyal, Deepak wrote: > > > Thx Nigel.. > > > > Also can you kindly advice how to turn autocommit to off > > Probably: > > SET AUTOCOMMIT TO OFF; > > although I'm not sure that is still there in 7.4 and there was a lot of > discussion on it's 'brokeness' I believe. I'm sure someone else will > correct me > if I'm wrong. I don't actually know as I've never used that feature, I > have > always used explicit transaction starts if I have wanted multistatement > transactions, and I can't remember the details of the discussion now. A > search > of the list archives should yield a collection of posts on this subject. I think you're right about "SET AUTOCOMMIT TO OFF" being removed from 7.4. In any case, what you want to is use transactions. I think the confusion occurs because in some (many?) client-side languages you inititiate a transaction by setting auto-commit to off (JDBC and ODBC do this) in the client-side driver. In the case of the PostgreSQL JDBC driver, this causes a BEGIN command to be sent to the server. I would imagine ODBC does the same. HTH -- Paul Thomas +------------------------------+---------------------------------------------+ | Thomas Micro Systems Limited | Software Solutions for the Smaller Business | | Computer Consultants | http://www.thomas-micro-systems-ltd.co.uk | +------------------------------+---------------------------------------------+