Lists: | pgsql-general |
---|
From: | "Bob Pawley" <rjpawley(at)shaw(dot)ca> |
---|---|
To: | "Postgresql" <pgsql-general(at)postgresql(dot)org> |
Subject: | Updating from a column |
Date: | 2010-01-18 19:31:57 |
Message-ID: | BC92B1E0A0B54AA19141934F8CAC0EAC@desktop |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
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
From: | Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Updating from a column |
Date: | 2010-01-18 20:20:22 |
Message-ID: | 201001181220.22812.adrian.klaver@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
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(dot)klaver(at)gmail(dot)com