Re: insert trigger - Mailing list pgsql-admin

From Bruno Wolff III
Subject Re: insert trigger
Date
Msg-id 20021107163334.GA17058@wolff.to
Whole thread Raw
In response to insert trigger  ("Roberto Benitez" <RBENITEZ@houston.rr.com>)
List pgsql-admin
On Mon, Nov 04, 2002 at 21:05:17 -0600,
  Roberto Benitez <RBENITEZ@houston.rr.com> 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
itright now..to find the last record inserted...is by sorting the primary key (serial) in descending order and taking
thefirst item in the list...the one at the top should be the one i just entered...and of course, i then procede to
updatethe 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
recordthat is inerted. what would happen if [ n ] different users try to insert records simultaniously? will psql
insertone-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.

pgsql-admin by date:

Previous
From:
Date:
Subject: Re: insert trigger
Next
From: "Gareth Kirwan"
Date:
Subject: Re: how could I get the source table name and field name from a view field