Re: Incorrect Query - Mailing list pgsql-novice

From Joshua b. Jore
Subject Re: Incorrect Query
Date
Msg-id Pine.BSO.4.44.0205080744420.7197-100000@kitten.greentechnologist.org
Whole thread Raw
In response to Incorrect Query  (Sharon Cowling <sharon.cowling@sslnz.com>)
List pgsql-novice
Sharon,
You were abusing parentheses and confusing the issue. Don't do that, it
just makes the query less readable.

Here is what you actually wrote:

where
person_id = ''
or
(
   (
       firstname = initcap('sharon')
   )
   or
   (
       lastname = initcap('cowling')
   )
)
or
(
   (
       firstname = initcap('sharon')
       and
       lastname = initcap('cowling')
   )
)

Which is simplified to (removing parentheses where redundant but
retaining all the logic). Check out that first bit where you match on
fname or lname. That last bit doesn't even do anything since the other
name expressions covered it already.

where
person_id = ''
or
firstname = initcap('sharon')
or
lastname = initcap('cowling')
or
(
   firstname = initcap('sharon')
   and
   lastname = initcap('cowling')
)

Why not just use?

WHERE person_id = ''
OR (firstname = initcap('sharon')
    AND
    lastname = initcap('cowling')
   )


pgsql-novice by date:

Previous
From: Andre Dubuc
Date:
Subject: Appending values non-destructively
Next
From: "Joshua b. Jore"
Date:
Subject: Re: Appending values non-destructively