dbTalk Databases Forums  

using OLD variable in DELETE trigger

comp.databases.postgresql.general comp.databases.postgresql.general


Discuss using OLD variable in DELETE trigger in the comp.databases.postgresql.general forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rick Casey
 
Posts: n/a

Default using OLD variable in DELETE trigger - 02-23-2005 , 03:42 PM






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 (AT) colorado (DOT) edu

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.