[NOVICE] Trigger unhappy

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[NOVICE] Trigger unhappy

Bendik Rognlien Johansen
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





---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

               http://www.postgresql.org/docs/faq
Reply | Threaded
Open this post in threaded view
|

Re: [despammed] [NOVICE] Trigger unhappy

Andreas Kretschmer
am  24.05.2005, um 10:48:14 +0200 mailte Bendik Rognlien Johansen folgendes:
>      IF NEW.indexed != true OR
                              ^^
                              why?

> What is causing this?

Im not sure, but this 'OR' is IMHO not correct.


Regards, Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: [despammed] [NOVICE] Trigger unhappy

Bendik Rognlien Johansen
Yes, sorry, I forgot to remove that "OR". It is not the problem.

On May 24, 2005, at 11:03 AM, Andreas Kretschmer wrote:

> am  24.05.2005, um 10:48:14 +0200 mailte Bendik Rognlien Johansen  
> folgendes:
>
>>      IF NEW.indexed != true OR
>>
>                               ^^
>                               why?
>
>
>> What is causing this?
>>
>
> Im not sure, but this 'OR' is IMHO not correct.
>
>
> Regards, Andreas
> --
> Andreas Kretschmer    (Kontakt: siehe Header)
> Heynitz:  035242/47212,      D1: 0160/7141639
> GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
>  ===    Schollglas Unternehmensgruppe    ===
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to  
> [hidden email]
>


---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
      subscribe-nomail command to [hidden email] so that your
      message can get through to the mailing list cleanly