Received: from alert.infoplease.com ([207.121.98.49]) by hub.org (8.9.3/8.9.3) with ESMTP id OAA45961; Fri, 25 Feb 2000 14:27:23 -0500 (EST) (envelope-from kdebisschop@range.infoplease.com) Received: from skillet.infoplease.com (skillet [10.0.1.212]) by alert.infoplease.com (8.9.3+Sun/8.9.3) with ESMTP id OAA04178; Fri, 25 Feb 2000 14:26:47 -0500 (EST) Received: (from kdebisschop@localhost) by skillet.infoplease.com (8.9.3/8.9.1) id OAA03223; Fri, 25 Feb 2000 14:26:48 -0500 Date: Fri, 25 Feb 2000 14:26:48 -0500 Message-Id: <200002251926.OAA03223@skillet.infoplease.com> X-Authentication-Warning: skillet.infoplease.com: kdebisschop set sender to kdebisschop@spaceheater.infoplease.com using -f From: Karl DeBisschop To: lylyeoh@mecomb.com CC: pgsql-hackers@postgreSQL.org, pgsql-general@postgreSQL.org In-reply-to: <3.0.5.32.20000225144132.008c4df0@pop.mecomb.po.my> (message from Lincoln Yeoh on Fri, 25 Feb 2000 14:41:32 +0800) Subject: Re: [GENERAL] Re: [HACKERS] TRANSACTIONS Reply-to: kdebisschop@range.infoplease.com References: <38B57564.46BB28C0@mindspring.com> <38B27760.DB921B57@sferacarta.com> <23935.951237171@sss.pgh.pa.us> <38B3E365.D2B61959@sferacarta.com> <200002231516.KAA23839@skillet.infoplease.com> <38B57564.46BB28C0@mindspring.com> <3.0.5.32.20000225144132.008c4df0@pop.mecomb.po.my> >>To summarize, I stated that the following does not work with >>postgresql: >> >>> $dbh->{AutoCommit} = 0; >>> $dbh->do("CREATE TABLE tmp (a int unique,b int)"); >>> $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; >> >>It's not that eval's error trapping is blown out - it's that the >>transaction defined by the AutoCommit cannot complete because a part >>of it cannot complete -- that's what atomicity means. > >Maybe I don't understand the situation. But it doesn't seem to be a big >problem. > >With postgres you have ensure that your application filters the data >properly before sticking it into the database. Then if the insert fails, >it's probably a serious database problem and in that case it's best that >the whole transaction is aborted anyway. This reason this idiom is used has nothing to do with validation. I agree that the application has the resopnsibility to cehck for valid data. The usefulness of the idion is that in a mutli-user environment, this is a basic way to update data that may or may not already have a key in the table. You can't do a "SELECT COUNT" because in the time between when you SELECT and INSERT (assuming the key is not already there) someone may have done a separate insert. The only other way I know to do this is to lock the entire table against INSERTs which has obvious performance effects. -- Karl DeBisschop 617.832.0332 (Fax: 617.956.2696) Information Please - your source for FREE online reference http://www.infoplease.com - Your Ultimate Fact Finder http://kids.infoplease.com - The Great Homework Helper Netsaint Plugins Development http://netsaintplug.sourceforge.net