From: | Roxanne Reid-Bennett <rox(at)tara-lu(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: Does psql evaluate OR conditions in order? |
Date: | 2013-01-16 23:41:17 |
Message-ID: | 50F73A9D.1090107@tara-lu.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On 1/16/2013 4:40 PM, Tom Lane wrote:
> HideMe <r36(at)tara-lu(dot)com> writes:
>> Postgres 9.1
>> Ubuntu something.
>> We have a stored procedure that performs the following evaluations:
>> IF ST_Intersects(line1, line2) OR ST_Intersects(line3, line4) THEN
>> do stuff
>> ELSIF ST_Intersects(line5, line6) OR ST_Intersects(line7, line8) THEN
>> do stuffB
>> END IF;
> In principle the order of ORs is not guaranteed, but that mainly has
> to do with execution of query WHERE clauses, wherein the optimizer
> will feel free to move sub-clauses to different relations, join
> levels, etc. I think you're reasonably safe to assume that OR is
> left-to-right in this simple context.
Thanks Tom... I knew the WHERE clause scenario was not guaranteed. I
just didn't know if the psql stored procedure conditional tests behaved
like C or ... not.
> IF ST_Intersects(line1, line2) THEN
> do stuff
> ELSIF ST_Intersects(line5, line6) THEN
> do stuffB
> ELSIF ST_Intersects(line3, line4) THEN
> do stuff
> ELSIF ST_Intersects(line7, line8) THEN
> do stuffB
> END IF;
> That doesn't look like it produces quite the same results ...
>
That would be true if you absolutely need the order initially given -
but in this case each ST_Intersects is a test for invalid data. This is
a collegue's sample, I asked hm ahead of time - order doesn't matter.
if any of the 4 conditions results, then invalid data exists in the
scenario and we have to do something about it... but only 1 condition
should ever be true.
again, thanks Tom.
Roxanne
From | Date | Subject | |
---|---|---|---|
Next Message | Gavan Schneider | 2013-01-17 00:26:59 | Re: Does psql evaluate OR conditions in order? |
Previous Message | Tom Lane | 2013-01-16 21:40:10 | Re: Does psql evaluate OR conditions in order? |