Pl/pgSQL trigger failing and i ant see why - Mailing list pgsql-general

From maurice.walshe@poptel.coop (Maurice Walshe)
Subject Pl/pgSQL trigger failing and i ant see why
Date
Msg-id 534cf093.0207240525.755d88d3@posting.google.com
Whole thread Raw
Responses Re: Pl/pgSQL trigger failing and i ant see why
List 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';

pgsql-general by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [SQL] Readline ... a lot of problems...
Next
From: Phil Davey
Date:
Subject: Re: RES: [SQL] Queries not using Index