Subject | Trigger Syntax |
---|---|
Author | myles@techsol.org |
Post date | 2007-04-03T06:04:01Z |
In order to improve performance on a query, I would like to add a trigger to
a table to automatically update a 'disply' field with some values. The
values would look like this:
'XX,YY,ZZ'
And are based on the number of related resources that are allocated to a
slot. My table structure looks kinda like this:
<ALLOCATION> 1 --- N <RESOURCES>
(but itÂ’s a bit more complex in real life). Each resource has Initials, and
this is what I want to show in the XX, YY, ZZ field. In order to do this, I
believe I will need a small stored procedure that can be called from within
a trigger, that will select all of the allocated resources, and then loop
through the rows returned, extracting the Initials and creating a string
variable, seperated by commas for display.
I can see the syntax for a WHILE loop in PSQL, however how do you associate
this with the number of rows returned from a SELECT statement? I need to
loop through each row returned and add to the string variable I'm
constructing.
All pointers greatly appreciated.
Thanks
Myles
============================
Myles Wakeham
Director of Engineering
Tech Solutions US, Inc.
Scottsdale, Arizona USA
Phone (480) 451-7440
www.techsol.org
a table to automatically update a 'disply' field with some values. The
values would look like this:
'XX,YY,ZZ'
And are based on the number of related resources that are allocated to a
slot. My table structure looks kinda like this:
<ALLOCATION> 1 --- N <RESOURCES>
(but itÂ’s a bit more complex in real life). Each resource has Initials, and
this is what I want to show in the XX, YY, ZZ field. In order to do this, I
believe I will need a small stored procedure that can be called from within
a trigger, that will select all of the allocated resources, and then loop
through the rows returned, extracting the Initials and creating a string
variable, seperated by commas for display.
I can see the syntax for a WHILE loop in PSQL, however how do you associate
this with the number of rows returned from a SELECT statement? I need to
loop through each row returned and add to the string variable I'm
constructing.
All pointers greatly appreciated.
Thanks
Myles
============================
Myles Wakeham
Director of Engineering
Tech Solutions US, Inc.
Scottsdale, Arizona USA
Phone (480) 451-7440
www.techsol.org