From: Tom Lane <tgl@sss.pgh.pa.us>
To: Grant Morgan <grant@ryuuguu.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: left joins
Date: Wed, 06 Jul 2005 10:44:14 -0400
Message-ID: <26225.1120661054@sss.pgh.pa.us> (raw)
In-Reply-To: <op.sthktgypuogdv0@localhost.localdomain>
References: <op.sthktgypuogdv0@localhost.localdomain>
"Grant Morgan" <grant@ryuuguu.com> writes:
> select count(*)
> from h left join p using (r,pos)
> where h.tn > 20
> and h.tn < 30
> and p.r_order=1
> since it is a left join I though I should get a number no smaller in
> the left join than the original unjoined query. It seems to be acting
> like an inner join.
Well, yeah. The condition p.r_order=1 will return NULL (effectively
FALSE) for any row in which p.r_order is NULL, so none of the
null-extended rows can survive the WHERE filter, so it's effectively
an inner join. Recent versions of PG actively recognize this case
and reduce the LEFT JOIN to plain JOIN, but even if we did not do that
you'd get the same result.
I've heard it claimed that Oracle produces different results; if true,
it must have something to do with their rather standards-challenged
interpretation of NULL ...
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, grant@ryuuguu.com
Subject: Re: left joins
In-Reply-To: <26225.1120661054@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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