pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Manfred Koizar <mkoi-pg@aon.at>
To: Lucas Adamski <ladamski@manageww.com>
Cc: Postgresql Performance Mailing list (E-mail) <pgsql-performance@postgresql.org>
Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT?
Date: Wed, 07 May 2003 22:22:54 +0200
Message-ID: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com> (raw)
In-Reply-To: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI>
References: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI>

On Wed, 7 May 2003 12:11:46 -0700, "Lucas Adamski"
<ladamski@manageww.com> 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 <anything> EXCEPT
<empty> should give the original result?

Servus
 Manfred




view thread (11+ messages)  latest in thread

Message-ID: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com>
Permalink:  ../5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com/
Also on:    postgresql.org/message-id/5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: mkoi-pg@aon.at, ladamski@manageww.com
  Subject: Re: Hack around lack of CORRESPONDING BY in EXCEPT?
  In-Reply-To: <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com>
  References: <000301c314cc$81c4ad20$11f5ec0c@LADAMSKI> <5npibv8l1090ppjkt17is5ipq26honl1e1@4ax.com>

* 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