Re: Updating from a column - Mailing list pgsql-general

From Adrian Klaver
Subject Re: Updating from a column
Date
Msg-id 201001181220.22812.adrian.klaver@gmail.com
Whole thread Raw
In response to Updating from a column  ("Bob Pawley" <rjpawley@shaw.ca>)
List 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.klaver@gmail.com

pgsql-general by date:

Previous
From: Thomas Kellerer
Date:
Subject: Re: Equivalent of mysql type mediablob in postgres?
Next
From: "Jean-Yves F. Barbier"
Date:
Subject: type of field