pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: John McKown <jmckown@prodigy.net>
To: Philip Warner <pjw@rhyme.com.au>
Cc: pgsql-sql@hub.org
Subject: Re: Operator Precedence problem?
Date: Sat, 12 Aug 2000 08:53:54 -0500 (CDT)
Message-ID: <Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net> (raw)
In-Reply-To: <3.0.5.32.20000812154918.01f4e1d0@mail.rhyme.com.au>

Every language that I've ever used (other than APL) has the precedence of
"or" being less than "and". So I would always expect the "and" clauses to
be evaluated first, then the "or". Just like in math, where in an
equation, I expect that the multiplication (and) is done before the
addition (or). Unless modified by parentheses just as in your second
example.

On Sat, 12 Aug 2000, Philip Warner wrote:

> 
> I have a peculiar problem that I can't reproduce on a trivial database:
> 
> select product, priority, count(*) as completed from issue 
> where
>     product = 'DIS' 
>     and create_date < '1-Aug-2000' and finish_date >= '1-Aug-2000' or
> finish_date is null
> group by product, priority;
> 
> This produces a list of all products - not just 'DIS'. If I put the last
> two clauses in parnthesis, then it works as expected:
> 
> select product, priority, count(*) as completed from issue 
> where
>     product = 'DIS' 
>     and create_date < '1-Aug-2000' and (finish_date >= '1-Aug-2000' or
> finish_date is null)
> group by product, priority;
> 
> Which makes me think that the precedence of 'or' is not what I expected. Is
> this a feature? If so, the fact that I get precisely the opposite behaviour
> in simple test databases must be a bug, I think.
> 
> Any help or explanation would be appreciated...
> 
> 
> 
> ----------------------------------------------------------------
> Philip Warner                    |     __---_____
> Albatross Consulting Pty. Ltd.   |----/       -  \
> (A.B.N. 75 008 659 498)          |          /(@)   ______---_
> Tel: (+61) 0500 83 82 81         |                 _________  \
> Fax: (+61) 0500 83 82 82         |                 ___________ |
> Http://www.rhyme.com.au          |                /           \|
>                                  |    --________--
> PGP key available upon request,  |  /
> and from pgp5.ai.mit.edu:11371   |/
> 




view thread (5+ messages)  latest in thread

Message-ID: <Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net>
Permalink:  ../Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net/
Also on:    postgresql.org/message-id/Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: jmckown@prodigy.net, pjw@rhyme.com.au, pgsql-sql@hub.org
  Subject: Re: Operator Precedence problem?
  In-Reply-To: <Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net>
  References: <3.0.5.32.20000812154918.01f4e1d0@mail.rhyme.com.au> <Pine.LNX.4.21.0008120851440.16858-100000@linux2.johnmckown.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox