[prev in list] [next in list] [prev in thread] [next in thread] 

List:       postgresql-admin
Subject:    [ADMIN] strange problem with plpgsql
From:       Richard NAGY <richard () presenceweb ! com>
Date:       2001-12-21 9:55:28
[Download RAW message or body]

hello,

I have a strange problem with a plpgsql function. Here is the code :

      create function tg_survey_au() returns opaque as '
      begin
        if new.dateexpire != old.dateexpire or new.email != old.email
then
           insert into survey_log values (
              current_timestamp,
              ''update'',
              new.idxsurvey,
              new.dateexpire,
              new.email
           );
         end if;
       return new;
      end;
      ' language 'plpgsql';

      create trigger tg_survey_au after update on survey for each row
execute procedure tg_survey_au();


The problem is about the 'or' in the if statement. I have tested the if
statement with just one condition. One with dateexpire and one with
email. It works very well. Then I have joined the two conditions in the
if statement with an 'or' like here in the code. Then, I have an insert
in survey_log just when the email change, not if the dateexpire change!
It seems that the 'or' does not work.

Any idea ?

Note : The tests have been tested on a postgresql version 7.0.2 on a
RedHat Linux 6.2 machine.

--
Richard NAGY
Presenceweb / Nameshield



[Attachment #3 (text/html)]

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
hello,
<p>I have a strange problem with a plpgsql function. Here is the code :
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; create function tg_survey_au() returns
opaque as '
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if new.dateexpire != old.dateexpire
or new.email != old.email then
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; insert
into survey_log values (
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
current_timestamp,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
''update'',
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
new.idxsurvey,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
new.dateexpire,
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
new.email
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end if;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return new;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; end;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' language 'plpgsql';
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; create trigger tg_survey_au after update
on survey for each row execute procedure tg_survey_au();
<br>&nbsp;
<p>The problem is about the 'or' in the if statement. I have tested the
if statement with just one condition. One with dateexpire and one with
email. It works very well. Then I have joined the two conditions in the
if statement with an 'or' like here in the code. Then, I have an insert
in survey_log just when the email change, not if the dateexpire change!
It seems that the 'or' does not work.
<p>Any idea ?
<p>Note : The tests have been tested on a postgresql version 7.0.2 on a
RedHat Linux 6.2 machine.
<pre>--
Richard NAGY
Presenceweb / Nameshield</pre>
&nbsp;</html>


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic