Skip site navigation (1) Skip section navigation (2)

Trigger unhappy

From: Bendik Rognlien Johansen <bendik(dot)johansen(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Trigger unhappy
Date: 2005-05-24 08:48:14
Message-ID: 1FFDA63B-1A67-488B-AFA8-8A17D0FD85A0@gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,
I have the following trigger on the table "records":

CREATE OR REPLACE FUNCTION records_update_trigger() RETURNS TRIGGER AS '
   BEGIN
     NEW.updated = now();
     IF OLD.address1 != NEW.address1 OR OLD.postalcode1 !=  
NEW.postalcode1
     THEN
       RAISE NOTICE ''Address was altered, position set to null'';
       NEW.position := NULL;
     END IF;


     IF NEW.indexed != true OR
     THEN
       NEW.indexed := false;
       RAISE NOTICE ''Index not set, unsetting indexed'';
     END IF;
     RETURN NEW;
   END;
' language plpgsql;

DROP TRIGGER update_trigger ON records;
CREATE TRIGGER update_trigger BEFORE UPDATE ON records FOR EACH ROW  
EXECUTE PROCEDURE records_update_trigger();



The "indexed" column on the table is default false.
Every time i do an update, the variable NEW.indexed is true, even  
when it is not set in the sql. The result is that indexed is never  
set to false in the second if-clause of the function.

What is causing this?


Thanks





Responses

pgsql-novice by date

Next:From: Bendik Rognlien JohansenDate: 2005-05-24 08:54:11
Subject: Trigger unhappy (Correction)
Previous:From: Jan B.Date: 2005-05-24 08:46:03
Subject: Re: "NOT NULL"

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group