pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Keith G. Murphy <keithmur@mindspring.com>
Cc: pgsql-hackers@postgreSQL.org
Cc: pgsql-general@postgreSQL.org
Subject: Re: [GENERAL] Re: [HACKERS] TRANSACTIONS
Date: Thu, 24 Feb 2000 12:16:04 -0600
Message-ID: <38B57564.46BB28C0@mindspring.com> (raw)
References: <38B27760.DB921B57@sferacarta.com>
	<23935.951237171@sss.pgh.pa.us>
	<38B3E365.D2B61959@sferacarta.com>
	<200002231516.KAA23839@skillet.infoplease.com>

Karl DeBisschop wrote:
> 
> >Sorry for my english, Tom, but the point is another, I'm talking
> >about transactions not about error messages.
> >
> >This is only a stupid example how to abort a transaction, PostgreSQL
> >aborts automatically transactions if an error occurs, even an warning
> >or a syntax error.
> >
> >I can believe that all other databases are wrong and only we
> >(PostgreSQL) are right, but please try to understand me. This is not
> >easy to believe anyway.
> >
> >I'm looking for another database with a behavior like PostgreSQL but
> >I can't find it, and I tried a lot of them until now.
> >
> >Do you know some database with transactions like PostgreSQL?
> 
> I personally don't feel qualified to interpret the standard.  But I
> would like to pipe in a little on the issue of what is desirable.
> 
> By default, as a developer, I would be quite unhappy with the behavior
> of those other databases (allowing a commit after an insert has
> failed).  If I do a bulk copy into an existing database, and one copy
> fails, that sort of behavior could concievably render my database
> unusable with not possibility of recovery. So in that sense, from the
> point of view of desirability I think postgres got it right.
> 
> But then I thought about if from a programming language point of
> view.  Consider the following code (I use perl/DBI as an example).
> 
> ========================= example =========================
> 
> $dbh->{AutoCommit} = 0;
> $dbh->do("CREATE TABLE tmp (a int unique,b int)");
> while (<>){
>     if (/([0-9]+) ([0-9]+)/) {
>         $rtv = $dbh->do("INSERT INTO tmp VALUES ($1,$2)");
>         if ($rtv) {$dbh->do("UPDATE tmp SET b=$2 where a=$1")};
>     }
> }
> $dbh->commit;
> $dbh->disconnect;
> 
> ========================= end ============================
> 
> This incorporates a very common idiom within a transaction block. Of
> course, this fails.  As far as I can tell from the preceding
> discussion, there is no way to "sanitize" the transaction once you
> have fixed the error. IMHO, it would be EXTREMELY useful to be able to
> implement the above transaction.  But not by default.
> 
> I'm not sure what a resonable syntax would be - several come to mind.
> You could have "SANITIZE TRANSACTION" or "\unset warning", whatever,
> the exact syntax matters little to me.  But without this sort of
> capability, people who do programatic error checking and correction
> (which seems like a good thing) are essentially penalized because they
> cannot effectively use transactions.
>
To continue with your example, this should work:

> $dbh->{AutoCommit} = 0;
> $dbh->do("CREATE TABLE tmp (a int unique,b int)");
> while (<>){
>     if (/([0-9]+) ([0-9]+)/) {
>         eval{$rtv = $dbh->do("INSERT INTO tmp VALUES ($1,$2)")};
>         if ($@) {$dbh->do("UPDATE tmp SET b=$2 where a=$1")};
>     }
> }
> $dbh->commit;
> $dbh->disconnect;

Sadly, it does not, as far as I can tell.  In fact, it seems to corrupt
the database to where you can't create the table tmp anymore, on my
system.  I certainly never get a table.

What's the rationale behind having the database blow out eval's error
trapping?  Can't see where letting a program recover from an error in a
statement compromises atomicity.
 
> Apologies if it is already possible to do this.
> 

Likewise.



view thread (58+ messages)  latest in thread

Message-ID: <38B57564.46BB28C0@mindspring.com>
Permalink:  ../38B57564.46BB28C0@mindspring.com/
Also on:    postgresql.org/message-id/38B57564.46BB28C0@mindspring.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-general@postgresql.org
  Cc: keithmur@mindspring.com, pgsql-hackers@postgreSQL.org
  Subject: Re: [GENERAL] Re: [HACKERS] TRANSACTIONS
  In-Reply-To: <38B57564.46BB28C0@mindspring.com>
  References: <38B27760.DB921B57@sferacarta.com> <23935.951237171@sss.pgh.pa.us> <38B3E365.D2B61959@sferacarta.com> <200002231516.KAA23839@skillet.infoplease.com> <38B57564.46BB28C0@mindspring.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