Thread: Updating from a column

Updating from a column

From
"Bob Pawley"
Date:
Hi
 
I have a table that has one column (pump1) controlled by a dbcheckbox. The values can be True, False or null.
 
I want to insert a row of values into second table when column pump1 value is 'True'. I don't want the trigger to insert a row when other columns of the first table are updated or when the pump1 column value becomes 'False'.
 
I would appreciate any suggestions as to how to accomplish this.
 
Thanks in advance.
 
Bob
 
 

Re: Updating from a column

From
Adrian Klaver
Date:
On Monday 18 January 2010 11:31:57 am Bob Pawley wrote:
> Hi
>
> I have a table that has one column (pump1) controlled by a dbcheckbox. The
> values can be True, False or null.
>
> I want to insert a row of values into second table when column pump1 value
> is 'True'. I don't want the trigger to insert a row when other columns of
> the first table are updated or when the pump1 column value becomes 'False'.
>
> I would appreciate any suggestions as to how to accomplish this.
>
> Thanks in advance.
>
> Bob

Create an INSERT, UPDATE trigger on table1. Have the trigger inspect the value
of pump1. You will need to guard against double entry on updates. So rough flow
is:

if TG_OP = 'INSERT' and NEW.pump1 = 't'
    INSERT row second table
if TG_OP = 'UPDATE' and NEW.pump1='t'
    if OLD.pump1 = 'f' or OLD.pump1 is NULL
        INSERT row second table



--
Adrian Klaver
adrian.klaver@gmail.com