Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 1E608476E4C for ; Thu, 7 Nov 2002 11:25:19 -0500 (EST) Received: from wolff.to (unknown [66.93.197.35]) by postgresql.org (Postfix) with SMTP id 4C36A4773F6 for ; Thu, 7 Nov 2002 11:23:55 -0500 (EST) Received: (qmail 17198 invoked by uid 500); 7 Nov 2002 16:33:34 -0000 Date: Thu, 7 Nov 2002 10:33:34 -0600 From: Bruno Wolff III To: Roberto Benitez Cc: pgsql-admin@postgresql.org Subject: Re: insert trigger Message-ID: <20021107163334.GA17058@wolff.to> Mail-Followup-To: Roberto Benitez , pgsql-admin@postgresql.org References: <000801c28478$2c97e810$6401a8c0@SUZIE> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <000801c28478$2c97e810$6401a8c0@SUZIE> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/90 X-Sequence-Number: 6278 On Mon, Nov 04, 2002 at 21:05:17 -0600, Roberto Benitez wrote: > I have the following situation: > > when a new record is inserted in to a psql table, i want to be able to update certain fields. the way i'm doing it right now..to find the last record inserted...is by sorting the primary key (serial) in descending order and taking the first item in the list...the one at the top should be the one i just entered...and of course, i then procede to update the fieldsd i need to update.. > So, basically would like to know if this will always work. will the one at the top (the one w/ the highest primary key [serial type]) always be the one i just entered. AND does psql ALWAYS execute the trigger(s) after EVERY single record that is inerted. what would happen if [ n ] different users try to insert records simultaniously? will psql insert one-execute the trigger, insert the next-execute the trigger..and so on? or will it insert ALL [n] records AND THEN execute the trigger? If you are writing an insert trigger the "new" record should have the value being inserted into serial column. You don't want to do a select for the highest value to get this value. Besides being less efficient, you have a more complicated locking situation to worry about.