trigger/function question - Mailing list pgsql-general

From Howard Williams
Subject trigger/function question
Date
Msg-id 9dn03g$p4u$1@news.tht.net
Whole thread Raw
List pgsql-general
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



pgsql-general by date:

Previous
From: Ed Loehr
Date:
Subject: Re: [PATCHES] Re: microsecond log timestamps
Next
From: Per-Olof Pettersson
Date:
Subject: DISTINCT ON () with UNION