Re: BUG #1371: Short-circuit evaluation on PL/PgSQL

Lists: pgsql-bugs
From: "Aguinaldo Possatto" <aguinaldo(at)aswti(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1371: Short-circuit evaluation on PL/PgSQL
Date: 2005-01-04 11:25:16
Message-ID: 200501041125.j04BPG0n026668@developer.pgadmin.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1371
Logged by: Aguinaldo Possatto
Email address: aguinaldo(at)aswti(dot)com
PostgreSQL version: 8.0
Operating system: Windows XP
Description: Short-circuit evaluation on PL/PgSQL
Details:

an exception is raised when this block is being executed:

if ( ((tg_op = 'INSERT') and
(new.field is not null)) or
((tg_op = 'DELETE') and
(old.field is not null)) )
then
...
end if;

the error is :
"SQL Error: ERRO: record "old" is not assigned yet"

but if the evaluation was "short-circuit" this error would not happen.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Aguinaldo Possatto" <aguinaldo(at)aswti(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1371: Short-circuit evaluation on PL/PgSQL
Date: 2005-01-05 06:58:55
Message-ID: 24478.1104908335@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Aguinaldo Possatto" <aguinaldo(at)aswti(dot)com> writes:
> an exception is raised when this block is being executed:

> if ( ((tg_op = 'INSERT') and
> (new.field is not null)) or
> ((tg_op = 'DELETE') and
> (old.field is not null)) )
> then
> ...
> end if;

> the error is :
> "SQL Error: ERRO: record "old" is not assigned yet"

> but if the evaluation was "short-circuit" this error would not happen.

The evaluation is not short-circuit, and is not going to become so.
See for instance
http://www.postgresql.org/docs/7.4/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL
The particular problem at hand here arises from different issues
(specifically that plpgsql has to push down all the variable values
it has at hand before the IF expression's evaluation can start)
but the fact remains that SQL does not promise short-circuit
evaluation.

regards, tom lane