If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > PostGreSQL Trigger Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-03-11, 06:32
vinodjayachandran vinodjayachandran is offline
Registered User
 
Join Date: Nov 2011
Posts: 1
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
Reply With Quote
  #2 (permalink)  
Old 11-24-11, 07:22
Wedgetail Wedgetail is offline
Registered User
 
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();
Reply With Quote
  #3 (permalink)  
Old 11-24-11, 08:06
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
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.
Reply With Quote
Reply

Tags
postgres 9.0.2, postgresql, trigger

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On