From: | wstrzalka <wstrzalka(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | plpgsql and logical expression evaluation |
Date: | 2008-04-22 09:41:50 |
Message-ID: | b26f6299-b09e-4bfb-850c-72fe2fa899e9@26g2000hsk.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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?
From | Date | Subject | |
---|---|---|---|
Next Message | D. Dante Lorenso | 2008-04-22 10:01:41 | How to modify ENUM datatypes? |
Previous Message | Clemens Schwaighofer | 2008-04-22 08:43:23 | Re: Postgres Encoding conversion problem |