pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Karl DeBisschop <kdebisschop@range.infoplease.com>
To: lylyeoh@mecomb.com
Cc: pgsql-hackers@postgreSQL.org
Cc: pgsql-general@postgreSQL.org
Subject: Re: [GENERAL] Re: [HACKERS] TRANSACTIONS
Date: Fri, 25 Feb 2000 14:26:48 -0500
Message-ID: <200002251926.OAA03223@skillet.infoplease.com> (raw)
In-Reply-To: <3.0.5.32.20000225144132.008c4df0@pop.mecomb.po.my>
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 <kdebisschop@alert.infoplease.com>
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



view thread (58+ messages)  latest in thread

Message-ID: <200002251926.OAA03223@skillet.infoplease.com>
Permalink:  ../200002251926.OAA03223@skillet.infoplease.com/
Also on:    postgresql.org/message-id/200002251926.OAA03223@skillet.infoplease.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: kdebisschop@range.infoplease.com, lylyeoh@mecomb.com, pgsql-hackers@postgreSQL.org
  Subject: Re: [GENERAL] Re: [HACKERS] TRANSACTIONS
  In-Reply-To: <200002251926.OAA03223@skillet.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> <3.0.5.32.20000225144132.008c4df0@pop.mecomb.po.my> <200002251926.OAA03223@skillet.infoplease.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