Search Postgresql Archives

Re: Updating from a column

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux