pgsql-general
❮
Not seeing script error
- Jump to comment-1Rich Shepard<rshepard@appl-ecosys.com>Jan 8, 2026, 4:43 PM UTCThe script:
select p.personnbr, p.fname, p.lname, p.jobtitle, p.direct_phone, p.email,
from people as pc.company_nbr, c.company_name, c.industry
inner join companies as c on p.companynbr = c.companynbr
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.personnbr, c.companynbr
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- Jump to comment-1Tom Lane<tgl@sss.pgh.pa.us>Jan 8, 2026, 4:48 PM UTCRich Shepard <rshepard@appl-ecosys.com> writes:
The script:
select p.personnbr, p.fname, p.lname, p.jobtitle, p.direct_phone, p.email,
c.companynbr, c.companyname, c.industry
from people as p
inner join companies as c on p.companynbr = c.companynbr
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.personnbr, c.companynbr
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?
where p.email is not null andAND binds more tightly than OR. I think you meant
(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- Jump to comment-1Rich Shepard<rshepard@appl-ecosys.com>Jan 8, 2026, 5:10 PM UTCOn Thu, 8 Jan 2026, Tom Lane wrote:
AND binds more tightly than OR. I think you meant
Tom,
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')
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 - Jump to comment-1Ron Johnson<ronljohnsonjr@gmail.com>Jan 8, 2026, 5:03 PM UTCOn 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.personnbr, p.fname, p.lname, p.jobtitle, p.direct_phone,p.email,
c.companynbr, c.companyname, c.industry
from people as p
inner join companies as c on p.companynbr = c.companynbr
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.personnbr, c.companynbr
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?
While missing parentheses would not break the logic.
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.
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!