pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
exists and is not null equivalence in query 2+ messages / 2 participants [nested] [flat]
* exists and is not null equivalence in query @ 2009-05-28 12:36 Raphael Bauduin <rblists@gmail.com> 2009-05-28 15:19 ` Re: exists and is not null equivalence in query Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 1 reply; 2+ messages in thread From: Raphael Bauduin @ 2009-05-28 12:36 UTC (permalink / raw) To: pgsql-sql Hi, In some code I am taking over, I found this query: 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? Thanks Raphaƫl -- Web database: http://www.myowndb.com Free Software Developers Meeting: http://www.fosdem.org ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: exists and is not null equivalence in query 2009-05-28 12:36 exists and is not null equivalence in query Raphael Bauduin <rblists@gmail.com> @ 2009-05-28 15:19 ` Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 2+ messages in thread From: Tom Lane @ 2009-05-28 15:19 UTC (permalink / raw) To: Raphael Bauduin <rblists@gmail.com>; +Cc: pgsql-sql 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 ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2009-05-28 15:19 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2009-05-28 12:36 exists and is not null equivalence in query Raphael Bauduin <rblists@gmail.com> 2009-05-28 15:19 ` Tom Lane <tgl@sss.pgh.pa.us>
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