public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Not seeing script error
3+ messages / 3 participants
[nested] [flat]

* Re: Not seeing script error
@ 2026-01-08 16:48 Tom Lane <[email protected]>
  2026-01-08 17:03 ` Re: Not seeing script error Ron Johnson <[email protected]>
  2026-01-08 17:10 ` Re: Not seeing script error Rich Shepard <[email protected]>
  0 siblings, 2 replies; 3+ messages in thread

From: Tom Lane @ 2026-01-08 16:48 UTC (permalink / raw)
  To: Rich Shepard <[email protected]>; +Cc: pgsql-general

Rich Shepard <[email protected]> writes:
> The script:
> select p.person_nbr, p.fname, p.lname, p.job_title, p.direct_phone, p.email,
>         c.company_nbr, c.company_name, c.industry
> from people as p
> inner join companies as c on p.company_nbr = c.company_nbr
> where p.email is not null and
> industry = 'Chemicals' or
> industry = 'Energy' or
> industry = 'Food processor' or
> industry = 'Manufacturing' or
> industry = 'Maritime' or
> industry = 'Transportation' or
> industry = 'Wood products'
> group by p.person_nbr, c.company_nbr
> order by p.person_nbr;

> The where condition, `p.email is not null' is not working; the results
> include rows where email is null while all other columns are okay.

> I had that condition following the industry conditions but that makes no
> difference.

> What have I missed?

AND binds more tightly than OR.  I think you meant

where p.email is not null and
(industry = 'Chemicals' or
industry = 'Energy' or
industry = 'Food processor' or
industry = 'Manufacturing' or
industry = 'Maritime' or
industry = 'Transportation' or
industry = 'Wood products')

BTW, using IN might make this more compact.

			regards, tom lane






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

* Re: Not seeing script error
  2026-01-08 16:48 Re: Not seeing script error Tom Lane <[email protected]>
@ 2026-01-08 17:03 ` Ron Johnson <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Ron Johnson @ 2026-01-08 17:03 UTC (permalink / raw)
  To: pgsql-general

On Thu, Jan 8, 2026 at 11:48 AM Tom Lane <[email protected]> wrote:

> Rich Shepard <[email protected]> writes:
> > The script:
> > select p.person_nbr, p.fname, p.lname, p.job_title, p.direct_phone,
> p.email,
> >         c.company_nbr, c.company_name, c.industry
> > from people as p
> > inner join companies as c on p.company_nbr = c.company_nbr
> > where p.email is not null and
> > industry = 'Chemicals' or
> > industry = 'Energy' or
> > industry = 'Food processor' or
> > industry = 'Manufacturing' or
> > industry = 'Maritime' or
> > industry = 'Transportation' or
> > industry = 'Wood products'
> > group by p.person_nbr, c.company_nbr
> > order by p.person_nbr;
>
> > The where condition, `p.email is not null' is not working; the results
> > include rows where email is null while all other columns are okay.
>
> > I had that condition following the industry conditions but that makes no
> > difference.
>
> > What have I missed?
>
> AND binds more tightly than OR.  I think you meant
>
> where p.email is not null and
> (industry = 'Chemicals' or
> industry = 'Energy' or
> industry = 'Food processor' or
> industry = 'Manufacturing' or
> industry = 'Maritime' or
> industry = 'Transportation' or
> industry = 'Wood products')
>
> BTW, using IN might make this more compact.
>

While missing parentheses would not break the logic.

-- 
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!


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

* Re: Not seeing script error
  2026-01-08 16:48 Re: Not seeing script error Tom Lane <[email protected]>
@ 2026-01-08 17:10 ` Rich Shepard <[email protected]>
  1 sibling, 0 replies; 3+ messages in thread

From: Rich Shepard @ 2026-01-08 17:10 UTC (permalink / raw)
  To: pgsql-general

On Thu, 8 Jan 2026, Tom Lane wrote:

> AND binds more tightly than OR.  I think you meant
> where p.email is not null and
> (industry = 'Chemicals' or
> industry = 'Energy' or
> industry = 'Food processor' or
> industry = 'Manufacturing' or
> industry = 'Maritime' or
> industry = 'Transportation' or
> industry = 'Wood products')

Tom,

While I'm aware that AND binds tigher than OR, I totally missed the need to
package all industry names within parentheses.

> BTW, using IN might make this more compact.

And, it enforces industry types to be in parentheses.

Thanks very much,

Rich






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


end of thread, other threads:[~2026-01-08 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-01-08 16:48 Re: Not seeing script error Tom Lane <[email protected]>
2026-01-08 17:03 ` Ron Johnson <[email protected]>
2026-01-08 17:10 ` Rich Shepard <[email protected]>

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