From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Mike Nolan <nolan(at)gw(dot)tssi(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org (pgsql general list) |
Subject: | Re: TG_OP and undefined OLD values |
Date: | 2005-08-26 16:49:20 |
Message-ID: | 10018.1125074960@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Mike Nolan <nolan(at)gw(dot)tssi(dot)com> writes:
> The following code fails because the OLD value is not defined:
> if TG_OP = ''INSERT''
> or (TG_OP = ''UPDATE'' and NEW.column1 != coalesce(OLD.column1,''--'')) then
> column2 := ''CHANGED'';
> end if;
> Shouldn't OLD.column1 not even be evaluated when the other if statement in
> the group in parentheses is false or when the earlier if statement is true?
No. Postgres does not guarantee short-circuit evaluation --- see
http://www.postgresql.org/docs/8.0/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL
In this particular case, even if the execution engine does things in the
order you want, you lose because plpgsql needs to plug in the parameter
values representing its variables before execution of the boolean
expression even begins.
So you'll have to break it into multiple IF commands.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Matt A. | 2005-08-26 16:58:07 | Re: Serials jumping |
Previous Message | sunil arora | 2005-08-26 16:43:04 | postgresql performance degradation over time.... |