pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Raymond Chui <Raymond.Chui@noaa.gov>
Cc: pgsql-sql@postgresql.org
Cc: pgadmin-support@postgresql.org
Cc: pgsql-general@postgresql.org
Cc: pgsql-admin@postgresql.org
Subject: Re: [ADMIN] How to execute my trigger when update certain columns
Date: 22 Aug 2002 07:10:27 +0100
Message-ID: <1029996627.31594.1742.camel@linda> (raw)
In-Reply-To: <3D5A487F.ECFECBAE@noaa.gov>
References: <3D5A487F.ECFECBAE@noaa.gov>

On Wed, 2002-08-14 at 13:09, Raymond Chui wrote:
> Let say I have a table has column1 and column2 and I made a trigger for
> after INSERT OR UPDATE for each row to execute procedure my_function.
> 
> What I want is the trigger execute my_function only when column1 is
> insert or
> update, but not going to execute my_function when column2 is insert or
> update.

The trigger is executed unconditionally, so put the condition inside
my_function.

If it's an INSERT, column1 must be new, so:

IF TG_OP = ''INSERT'' OR
  (TG_OP = ''UPDATE'' AND
     (NEW.column1 != OLD.column1 OR
       (NEW.column1 IS NULL AND OLD.column1 IS NOT NULL) OR 
       (NEW.column1 IS NOT NULL AND OLD.column1 IS NULL)
     )
  ) THEN
...
END IF;

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight, UK                            
http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
                 ========================================
     "For yourselves know perfectly that the day of the Lord
      so cometh as a thief in the night. For when they shall
      say, Peace and safety; then sudden destruction cometh 
      upon them, as travail upon a woman with child; and 
      they shall not escape."      I Thessalonians 5:2,3 




view thread (2+ messages)

Message-ID: <1029996627.31594.1742.camel@linda>
Permalink:  ../1029996627.31594.1742.camel@linda/
Also on:    postgresql.org/message-id/1029996627.31594.1742.camel@linda

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: olly@lfix.co.uk, Raymond.Chui@noaa.gov, pgadmin-support@postgresql.org, pgsql-general@postgresql.org, pgsql-admin@postgresql.org
  Subject: Re: [ADMIN] How to execute my trigger when update certain columns
  In-Reply-To: <1029996627.31594.1742.camel@linda>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox