pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Roberto Benitez <RBENITEZ@houston.rr.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: insert trigger
Date: Thu, 7 Nov 2002 10:33:34 -0600
Message-ID: <20021107163334.GA17058@wolff.to> (raw)
In-Reply-To: <000801c28478$2c97e810$6401a8c0@SUZIE>
References: <000801c28478$2c97e810$6401a8c0@SUZIE>

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 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.



view thread (5+ messages)

Message-ID: <20021107163334.GA17058@wolff.to>
Permalink:  ../20021107163334.GA17058@wolff.to/
Also on:    postgresql.org/message-id/20021107163334.GA17058@wolff.to

 · 

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-admin@postgresql.org
  Cc: bruno@wolff.to, RBENITEZ@houston.rr.com
  Subject: Re: insert trigger
  In-Reply-To: <20021107163334.GA17058@wolff.to>
  References: <000801c28478$2c97e810$6401a8c0@SUZIE> <20021107163334.GA17058@wolff.to>

* 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