Received: from news.tht.net (news.hub.org [216.126.91.242]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f4DMR8A32393 for ; Sun, 13 May 2001 18:27:08 -0400 (EDT) (envelope-from news@news.tht.net) Received: (from news@localhost) by news.tht.net (8.11.1/8.11.1) id f4DLxEM25761 for pgsql-general@postgresql.org; Sun, 13 May 2001 17:59:14 -0400 (EDT) (envelope-from news) From: "Howard Williams" X-Newsgroups: comp.databases.postgresql.questions Subject: trigger/function question Date: Sun, 13 May 2001 14:57:38 -0700 Organization: Hub.Org Networking Services (http://www.hub.org) Lines: 28 Message-ID: <9dn03g$p4u$1@news.tht.net> X-Complaints-To: scrappy@hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 To: pgsql-general@postgresql.org X-Archive-Number: 200105/587 X-Sequence-Number: 9446 Hello there! I need to perform a one-to-many insert based on the insert or update on a table. I'm not sure if it's possible without a loadable c module. I'm hoping it is. Can't find a built-in looping mechanism. I have tables A, B, and C. On every update or insert on A, I need to insert a row in B for every row in C. Here's a skeleton of my plan: CREATE FUNCTION line_items_trig_func ( character varying(20), character varying(20), character varying(50), character varying(500), character varying(40), int2, int4, int4, int4, character varying(20), int2, timestamp, bool, character varying(20) ) returns boolean as '' (some kind of for each in (select * from C) (insert intoB))" LANGUAGE 'sql'; CREATE TRIGGER line_items_trigger AFTER INSERT or UPDATE on line_items FOR EACH STATEMENT EXECUTE PROCEDURE ('col1', 'col2', ...); Thanks, howie