From: Tom Lane <tgl@sss.pgh.pa.us>
To: Raphael Bauduin <rblists@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: exists and is not null equivalence in query
Date: Thu, 28 May 2009 11:19:04 -0400
Message-ID: <9371.1243523944@sss.pgh.pa.us> (raw)
In-Reply-To: <f5227160905280536u4f131850pad984218b0fe8b5@mail.gmail.com>
References: <f5227160905280536u4f131850pad984218b0fe8b5@mail.gmail.com>
Raphael Bauduin <rblists@gmail.com> writes:
> select count(t.trame_id) as count, v.voiture_num as voitureNum from
> arch_trames t left join voiture v on (v.tag_id=t.tag_id)
> where
> (t.recept_time >= 1243509320691)
> and exists (select v2.voiture_num from voiture v2 where v2.tag_id=v.tag_id)
> group by v.voiture_num order by v.voiture_num
> Am I right that I can replace the "and exists..." clause by
> "and v.voiture_num is not null " in this case?
Well, more like "and v.tag_id is not null". But yes, the EXISTS seems
pretty stupid. Also, having done that, the left join reduces to a plain
inner join and you don't even need the NOT NULL. IOW this should just be
select count(t.trame_id) as count, v.voiture_num as voitureNum from
arch_trames t join voiture v on (v.tag_id=t.tag_id)
where (t.recept_time >= 1243509320691)
group by v.voiture_num order by v.voiture_num
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, rblists@gmail.com
Subject: Re: exists and is not null equivalence in query
In-Reply-To: <9371.1243523944@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