From: | Derrick Betts <list(at)blueaxis(dot)com> |
---|---|
To: | "pgsql-novice(at)postgresql(dot)org" <pgsql-novice(at)postgresql(dot)org> |
Subject: | Multiple row update with trigger |
Date: | 2007-05-21 18:53:36 |
Message-ID: | 4651EAB0.7030604@blueaxis.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
I have a table with a primary key for each row, and a group
identification number (groupid) which is not necessarily unique, for
each row. As such, I may have 3-5 rows with the same groupid.
Anytime a row is updated, I need a trigger to update any other rows with
the same groupid as the NEW row that is being updated.
For example, rows 1, 2 & 3 all share the same groupid:
Anytime row 1 is updated, I need row 2 and 3 updated with the same
information as row 1.
Anytime row 2 is updated, I need row 1 and 3 updated with the same
information as row 2.
Anytime row 3 is updated, I need row 1 and 2 updated with the same
information as row 3.
I would like to use a trigger, but the only way I can see updating the
"additional" rows is with the NEW variable, and this is only visible on
a FOR EACH ROW trigger. This causes problems in that the trigger will
get caught in an infinite loop as it begins updating the additional rows.
The other alternative is a FOR EACH STATEMENT trigger. However, the
values that are being updated in the NEW row aren't visible to this type
of trigger to allow me to update the other rows.
Does anyone have any good ideas as to how I might solve this problem?
Perhaps even taking a completely different approach in some way?
Thanks,
Derrick
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Kretschmer | 2007-05-21 19:05:51 | Re: Multiple row update with trigger |
Previous Message | Raimon Fernandez | 2007-05-21 18:40:29 | Re: aggregate function ? |