pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Order of precedence between AND and OR.
2+ messages / 2 participants
[nested] [flat]

* Order of precedence between AND and OR.
@ 2005-11-25 16:52  David Pradier <david.pradier@clarisys.fr>
  0 siblings, 1 reply; 2+ messages in thread

From: David Pradier @ 2005-11-25 16:52 UTC (permalink / raw)
  To: pgsql-sql

Hi everybody,

during the code inspection due to our migration to 8.1,
I found a piece of SQL code written like this :

WHERE a AND b OR c AND d

Now, I know that AND and OR are commutative because it's written in the
docs.
But what I couldn't find is if there is an order of precedence between
AND and OR, that is if the AND expression is calculated before the OR
one, or anyelse way.

Could somebody tell me or point me to the right doc ?

Thanks in advance,
David

-- 
David Pradier -- Directeur Technique de Clarisys Informatique -- Chef de projet logiciels libres / open-source



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Order of precedence between AND and OR.
@ 2005-11-25 19:59  Tom Lane <tgl@sss.pgh.pa.us>
  parent: David Pradier <david.pradier@clarisys.fr>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2005-11-25 19:59 UTC (permalink / raw)
  To: David Pradier <david.pradier@clarisys.fr>; +Cc: pgsql-sql

David Pradier <david.pradier@clarisys.fr> writes:
> But what I couldn't find is if there is an order of precedence between
> AND and OR, that is if the AND expression is calculated before the OR
> one, or anyelse way.

AND first; see
http://www.postgresql.org/docs/8.1/static/sql-syntax.html#SQL-PRECEDENCE
This is required by the SQL spec.

But you probably also want to read
http://www.postgresql.org/docs/8.1/static/sql-expressions.html#SYNTAX-EXPRESS-EVAL

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-11-25 19:59 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-11-25 16:52 Order of precedence between AND and OR. David Pradier <david.pradier@clarisys.fr>
2005-11-25 19:59 ` Tom Lane <tgl@sss.pgh.pa.us>

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