Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Unanswered: PostGreSQL Trigger Help

    Hi

    I need some help in writing PostGreSQL Trigger.
    I need to write trigger as below

    CREATE TRIGGER WMTbhk242b AFTER INSERT ON public.testtable FOR EACH ROW
    BEGIN
    INSERT INTO WMBbhk242b (c1, wm_rowid) VALUES (:new.c1, WMSbhk242b.NEXTVAL);
    END;". "

    But postgre expects EXECUTE PROCEDURE . I create the trigger dynamically from my code, so I am unable to create a procedure prior to creating this trigger

  2. #2
    Join Date
    Feb 2009
    Posts
    29
    Hi vinodjayachandran,

    PostgreSQL requires a Function to be defined as a Trigger procedure, then added to a Table as a Trigger.

    eg. Create the Function
    Code:
    Create or Replace Function WMTbhk242b () RETURNS TRIGGER AS $WMTbhk242b$
    BEGIN
          INSERT INTO WMBbhk242b (c1, wm_rowid) VALUES (:new.c1, WMSbhk242b.NEXTVAL);
    END;
    $WMTbhk242b$ LANGUAGE plpgsql STABLE;
    Add the Trigger to the Table
    Code:
    CREATE TRIGGER trigger_name AFTER INSERT ON public.testtable
      FOR EACH ROW EXECUTE PROCEDURE WMTbhk242b();

  3. #3
    Join Date
    Nov 2003
    Posts
    2,935
    Provided Answers: 12
    Quote Originally Posted by vinodjayachandran View Post
    I create the trigger dynamically from my code, so I am unable to create a procedure prior to creating this trigger
    Well, then your code needs to create the procedure and the trigger dynamically.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •