Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql General > plpgsql and log...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 6 Topic 15348 of 17598
Post > Topic >>

plpgsql and logical expression evaluation

by wstrzalka <wstrzalka@[EMAIL PROTECTED] > Apr 22, 2008 at 02:41 AM

One of the annoying things in plpgsql is logical expression
evaluation.

In most (all??) languages I know, logical expression like:

     if ( [A_true_expression] or [B_false_expression] ) then

will stop evaluating when the A expression will be evaluated as a
TRUE.
So the B will be not checked. In plpgsql it's different - all the
expressions are evaluated.


Why I don't like it? One of the samples is trigger procedure called
with body like this:

IF (TG_OP = 'INSERT' OR (TG_OP = 'UPDATE' AND NEW.status <>
OLD.status)) THEN
        -- DO SOMETHING
END IF;

It don't work for insert as the part designed for UPDATE will be
evaluated, while there is no OLD for an insert operation.
So the code looks like that:

IF (TG_OP = 'INSERT') THEN
        -- DO SOMETHING
ELSIF  (TG_OP = 'UPDATE' AND NEW.status <> OLD.status) THEN
        -- DO THE SAME AS ABOVE
END IF;


Is there any reason for that like side effects (please give me any
example?) or it's just not yet done optimization?
 




 6 Posts in Topic:
plpgsql and logical expression evaluation
wstrzalka <wstrzalka@[  2008-04-22 02:41:50 
Re: plpgsql and logical expression evaluation
kleptog@[EMAIL PROTECTED]  2008-04-23 10:39:54 
Re: plpgsql and logical expression evaluation
alvherre@[EMAIL PROTECTED  2008-04-23 08:57:59 
Re: plpgsql and logical expression evaluation
tgl@[EMAIL PROTECTED] (T  2008-04-23 10:32:20 
Re: plpgsql and logical expression evaluation
wstrzalka <wstrzalka@[  2008-04-23 08:39:59 
Re: plpgsql and logical expression evaluation
tgl@[EMAIL PROTECTED] (T  2008-04-24 11:10:44 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Mon Dec 1 8:31:10 CST 2008.