Pl/pgSQL trigger failing and i ant see why

From: maurice(dot)walshe(at)poptel(dot)coop (Maurice Walshe)
To: pgsql-general(at)postgresql(dot)org
Subject: Pl/pgSQL trigger failing and i ant see why
Date: 2002-07-24 13:25:07
Message-ID: 534cf093.0207240525.755d88d3@posting.google.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

HI all

I have read the skimpy docs on postgres triggers and whilst I can
get a simple trigger working when I try to call a Pl/pgsql function
to return the value I want to set one of the foields in NEW to it wont
work.

immediateparentid_ is INT4

This fails NEW.immediateparentid_ := FindRealParent(NEW.messageid_) ;
This works NEW.immediateparentid_ := 123456 ;

Here are the function's btw I have tested the interactivlky so they
are returning coorect values.

Any one got any ideas? BTW WTF does postgres hide its logs?

Best Regards

Maurice

CREATE FUNCTION FindRealParent(INTEGER) returns INTEGER as '
DECLARE
realid INTEGER;
BEGIN
realid := findbyref($1);
IF realid = 0 THEN
realid := findbysubject($1);
END IF;
RETURN realid;
END;
' LANGUAGE 'plpgsql';

CREATE TRIGGER SetMsgParent BEFORE INSERT on messages_
FOR EACH ROW EXECUTE PROCEDURE SetMsgParent();

CREATE FUNCTION SetMsgParent () returns OPAQUE as '
BEGIN
NEW.immediateparentid_ := FindRealParent(NEW.messageid_) ;
RETURN NEW;
END;
' LANGUAGE 'plpgsql';

CREATE FUNCTION FindRealParent(INTEGER) returns INTEGER as '
DECLARE
realid INTEGER;
BEGIN
realid := findbyref($1);
IF realid = 0 THEN
realid := findbysubject($1);
END IF;
RETURN realid;
END;
' LANGUAGE 'plpgsql';

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ray Hunter 2002-07-24 13:42:55 Re: Security, IP and username restrictions
Previous Message Jorge Sarmiento 2002-07-24 13:21:03 Error while recovering a database