X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 745D0476583 for ; Wed, 7 May 2003 16:23:06 -0400 (EDT) Received: from email06.aon.at (WARSL401PIP3.highway.telekom.at [195.3.96.75]) by postgresql.org (Postfix) with SMTP id DA47F476582 for ; Wed, 7 May 2003 16:23:04 -0400 (EDT) Received: (qmail 182930 invoked from network); 7 May 2003 20:23:05 -0000 Received: from m156p012.dipool.highway.telekom.at (HELO cantor) ([62.46.9.108]) (envelope-sender ) by qmail6rs.highway.telekom.at (qmail-ldap-1.03) with SMTP for ; 7 May 2003 20:23:05 -0000 From: Manfred Koizar To: "Lucas Adamski" Cc: "Postgresql Performance Mailing list (E-mail)" Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT? Date: Wed, 07 May 2003 22:22:54 +0200 Message-ID: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com> References: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> X-Mailer: Forte Agent 1.8/32.548 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Spam-Status: No, hits=-32.2 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,REFERENCES, REPLY_WITH_QUOTES,USER_AGENT_FORTE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/92 X-Sequence-Number: 1871 On Wed, 7 May 2003 12:11:46 -0700, "Lucas Adamski" wrote: >I have two tables: an event table that logs random events as they come in, >and a tracking table that keeps a state of events it cares about. In this >particular case I'm trying to obtain a list of tracking pkeys for related >event data that do not correspond to a certain (other) set of event data. > >Ideally, here is what I want: > >SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE >tracking.event_fk = event.pk EXCEPT (SELECT events.data1,events.data2 FROM >events WHERE event.type = 10) Lucas, try this untested query: SELECT tr.pk, ev.data1, ev.data2 FROM tracking tr INNER JOIN events ev ON tr.event_fk = ev.pk WHERE ev.type != 10; (Should also work with AND instead of WHERE.) >SELECT tracking.pk,events.data1,events.data2 FROM tracking,events WHERE >tracking.event_fk = event.pk EXCEPT (SELECT >tracking.pk,events.data1,events.data2 FROM tracking,events WHERE >tracking.event_fk = event.pk AND event.type = 10) > >That won't work for two reasons... first, there are no matching entries in >the tracking table pointing to events where event.type = 10, meaning this >query would always return an empty set. I don't understand this. If there are no entries with event.type 10, then the subselect returns an empty result set, and EXCEPT should give the original result? Servus Manfred