Re: [SQL] Operator Precedence problem?

2000-08-12 Thread Tom Lane

Philip Warner <[EMAIL PROTECTED]> writes:
> Which makes me think that the precedence of 'or' is not what I
> expected.

OR is certainly lower-precedence than AND --- this is hard-wired in the
grammar and not subject to change across databases.  It's also required
by SQL92:

  ::=

  |  OR 

  ::=

  |  AND 

  ::=
  [ NOT ] 

  ::=
   [ IS [ NOT ]  ]

  ::=
TRUE
  | FALSE
  | UNKNOWN

  ::=

  |   

BTW, I notice that we do not correctly implement the IS tests.
The parser turns them into " = 't'::bool" and so on,
which is wrong because it will yield NULL for NULL input, which
is contrary to the spec for these tests.  We need specialized
functions comparable to the ones for IS NULL (in fact, IS UNKNOWN
should be equivalent to IS NULL except for requiring a boolean
input, AFAICT).

regards, tom lane



Re: [SQL] Week of the Year?

2000-08-12 Thread John McKown

Sorry,
I don't speak TCL or TK. I've got a book on it, but I haven't had any time
or pressing need to get familiar with it. I'm learning Python & PHP. Well,
at least I'm trying to whenever I can find a spare moment (which is rare).

On Sat, 12 Aug 2000, David Lloyd-Jones wrote:

> John,
> 
> Many thanks. What I actually need is to present the five weekdays of a week
> beginning with Sunday on a drop-down box in TCL; then have a person click on
> any day and get sales for that day, or on a thing at the bottom to get sales
> for the week
> 
> Do you TCL? Can you give me any clues on drop-down boxes, and how to get
> the -U, Linux week-of-the-year, into them?
> 
>   Best wishes,
> 
>   -dlj.
> 
> Hey, I didn't know Prodigy still existed!
> 
> 
> 
> 
> 
> - Original Message -
> From: "John McKown" <[EMAIL PROTECTED]>
> To: "David Lloyd-Jones" <[EMAIL PROTECTED]>
> Cc: <[EMAIL PROTECTED]>
> Sent: Friday, August 11, 2000 10:55 PM
> Subject: Re: [SQL] Week of the Year?
> 
> 
> >
> > Try using the function date_part such as:
> >
> > select date_part('week',now());
> >
> > "and the days that are in that week" I guess want to answer a question
> > such as:
> > Given a date, what is first date in that same week, and what is the last
> > date in that week. There are a couple of approaches to this. My first was:
> >
> > select
> > to_date(date_part('year',now()),'')+(7*date_part('week',now()));
> >
> > and the above +6 to the the last day of the week. Another approach for
> > this same question is much simplier (if the question is indeed what you
> > are asking)
> >
> > select now()-date_part('dow',now());
> >
> > This last select gives the Sunday for the current week. To get the
> > Saturday, simply:
> >
> > select now()-date_part('dow',now())+6;
> >
> > Of course, replace the now() with whatever contains the date or timestamp.
> >
> > John McKown
> >
> > > I'm probably staring right at it. (One of the difficulties with RTFMing,
> is
> > > having too many docs!)
> > >
> > > Is there anything in the API that produces the week of the year, from 1
> to
> > > 52 or 53 depending on the week of the year, and the days that are in
> that
> > > week?
> > >
> > > Many thanks.
> > >
> > >   -dlj.
> > >
> > >
> > >
> >
> >
> 





Re: [SQL] Operator Precedence problem?

2000-08-12 Thread John McKown

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   |/
> 




Re: [SQL] Operator Precedence problem?

2000-08-12 Thread Philip Warner

At 08:53 12/08/00 -0500, John McKown wrote:
>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.

You're quite right; I think I must have been punch drunk from beating my
head against another problem. Thanks.



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   |/