Received: from mailsys01.intnet.net (mailhost.wwc.com [198.252.32.15]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f49LtrA39487 for ; Wed, 9 May 2001 17:55:53 -0400 (EDT) (envelope-from jconway2@home.com) Received: from [206.19.64.3] (HELO jecw2k1) by mailsys01.intnet.net (CommuniGate Pro SMTP 3.3.2) with SMTP id 7902147; Wed, 09 May 2001 17:55:01 -0400 Message-ID: <000c01c0d8d2$cefddf90$54d410ac@jecw2k1> From: "Joe Conway" To: "Joseph Shraibman" , References: <3AF9AECE.DE93E098@selectacast.net> Subject: Re: 'record old is unassigned yet' when using trigger in 7.1.1 Date: Wed, 9 May 2001 14:55:48 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 X-Archive-Number: 200105/65 X-Sequence-Number: 2866 > begin > IF OLD.status <> NEW.status > THEN > NEW.statchangedate = CURRENT_DATE; > END IF; > return NEW; > end; > > The problem is when a new row is inserted I get this error message: > ERROR: record old is unassigned yet > ... and the insert fails. > > It doesn't matter if the trigger is before or after. OLD doesn't exist on inserts, only on update and delete. If you want to use the same function for both insert and update use the TG_OP variable and an if statement. See http://www.postgresql.org/idocs/index.php?plpgsql-trigger.html Hope this helps, Joe