Thread

  1. Not seeing script error

    Rich Shepard <rshepard@appl-ecosys.com> — 2026-01-08T16:43:23Z

    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?
    
    TIA,
    
    Rich
    
    
    
    
  2. Re: Not seeing script error

    Tom Lane <tgl@sss.pgh.pa.us> — 2026-01-08T16:48:47Z

    Rich Shepard <rshepard@appl-ecosys.com> 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
    
    
    
    
  3. Re: Not seeing script error

    Ron Johnson <ronljohnsonjr@gmail.com> — 2026-01-08T17:03:29Z

    On Thu, Jan 8, 2026 at 11:48 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
    
    > Rich Shepard <rshepard@appl-ecosys.com> 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!
    
  4. Re: Not seeing script error

    Rich Shepard <rshepard@appl-ecosys.com> — 2026-01-08T17:10:06Z

    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