Connecting Tech Pros Worldwide Help | Site Map

using OLD variable in DELETE trigger

  #1  
Old November 23rd, 2005, 03:03 AM
Rick Casey
Guest
 
Posts: n/a
Hello,

I am trying to get a trigger to fire when a record is deleted that will
record the deleted record in a history file. Here is the trigger code:


CREATE OR REPLACE FUNCTION logPedigreesDel() RETURNS TRIGGER AS '
begin
INSERT INTO PEDIGREES_hist(
PedigreeID,
ProjectID,
prev_PedID,
prev_FamIndID,
prev_FamID,
prev_IndID,
prev_FatherID,
prev_MotherID,
prev_Sex,
prev_Age,
prev_Dna,
prev_Diagnosis,
prev_StatusBroad,
prev_StatusNarrow,
prev_LiabilityClass,
prev_Exclude,
prev_ModDate,
prev_ModBy,
InsertDate)
VALUES (
OLD.PedigreeID,
OLD.ProjectID,
OLD.PedID,
OLD.FamIndID,
OLD.FamID,
OLD.IndID,
OLD.FatherID,
OLD.MotherID,
OLD.Sex,
OLD.Age,
OLD.Dna,
OLD.Diagnosis,
OLD.StatusBroad,
OLD.StatusNarrow,
OLD.LiabilityClass,
OLD.Exclude,
OLD.ModDate,
OLD.ModBy,
OLD.InsertDate);
end;
' LANGUAGE plpgsql;

However, here is the error message when the trigger fires:

psql:testphdtrig.sql:1: ERROR: record "old" is not assigned yet
DETAIL: The tuple structure of a not-yet-assigned record is indeterminate.
CONTEXT: PL/pgSQL function "logpedigreesdel" line 2 at SQL statement

OLD is supposed to be an automatically created variable, datatype
record, and about a dozen examples I've seen use the OLD variable in
this way without having to declare anything.

Can anyone tell me what I'm doing wrong?

thanks mucho,
Rick
--
Rick Casey, Research Associate
Institute for Behavioral Genetics
rick.casey@colorado.edu
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
trigger problem joy answers 1 June 27th, 2008 06:34 PM
How to do...well...anything...in DB2 SQL Ian Boyd answers 138 April 8th, 2006 12:45 AM
ON DELETE trigger blocks delete from my table Naeem Bari answers 4 November 23rd, 2005 02:39 AM
trigger problem joy answers 1 July 19th, 2005 10:21 PM