pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Gamache <cgg007@yahoo.com>
To: pgsql-odbc@postgresql.org
Subject: Re: Can I do anything to prevent " auto rollback in a transaction when an error occurs "
Date: Fri, 21 Mar 2003 05:51:06 -0800 (PST)
Message-ID: <20030321135106.68829.qmail@web13804.mail.yahoo.com> (raw)
In-Reply-To: <200303210413.h2L4D5Jb020559@mail.bacchus.com.au>

There's no reason to go breaking transactions when you can SQL around this
problem. The whole point of transactions are to rollback on error! :)

Here's one way around it...

-- first independant transaction
BEGIN;
insert  t1 values(1);
COMMIT;
-- second independant transaction
BEGIN;
delete from t2
COMMIT;
-- third independant transaction
BEGIN;
insert t1 values(2);
COMMIT;

Here's another way around it

-- try to create the table
-- if it exists transaction will rollback
BEGIN;
create table t2 (myval int4);
COMMIT;

-- this transaction will commit now.
BEGIN;
insert  t1 values(1);
delete from t2
insert t1 values(2);
COMMIT;

You might even create a function called deleteallifexists('tablename') and have
it check the pg_tables.tablename field for the table in question, and if it
exists, then do a delete.

CG

--- Wayne Armstrong <wdarmst@bacchus.com.au> wrote:
> ** Reply to message from "junzeng" <junzeng@netease.com> on Fri, 21 Mar 2003
> 11:00:39 +0800
> 
> Hi,
>  If you set the dissalow premature option in the odbc driver it can reduce
> the
> risk of this - but it still does happen and it's extremely dangerous :(.
>  I have hacked the odbc driver (for the 7.72.0.5 level) to work with
> visualage
> smalltalk, and have removed the rollback on error with no obvious bad side
> effects. (there probably are some though).
> 
> Regards,
> Wayne
>  
> > In a transaction , if a sql command invite an error , all commands before
> this
> > command will be rollbacked , and the transaction reset and restart. 
> > For example:
> >  
> > BEGIN
> > insert  t1 values(1);
> > delete from t2
> > insert t1 values(2);
> > commit
> > 
> > if table t2 doesn't exist , "delete from t2" invites an error , and the
> insert will be rollbacked . 
> > 
> > How can I prevent the rollback even when an error occurs ? Thanks
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
> http://www.postgresql.org/docs/faqs/FAQ.html



__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com



view thread (3+ messages)

Message-ID: <20030321135106.68829.qmail@web13804.mail.yahoo.com>
Permalink:  ../20030321135106.68829.qmail@web13804.mail.yahoo.com/
Also on:    postgresql.org/message-id/20030321135106.68829.qmail@web13804.mail.yahoo.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-odbc@postgresql.org
  Cc: cgg007@yahoo.com
  Subject: Re: Can I do anything to prevent " auto rollback in a transaction when an error occurs "
  In-Reply-To: <20030321135106.68829.qmail@web13804.mail.yahoo.com>
  References: <200303210413.h2L4D5Jb020559@mail.bacchus.com.au> <20030321135106.68829.qmail@web13804.mail.yahoo.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox