pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
Cc: Allan Kamau <allank@sanbi.ac.za>
Cc: pgsql-sql@postgresql.org
Subject: Re: Removing redundant itemsets
Date: Mon, 31 Mar 2008 19:48:34 +0800
Message-ID: <47F0CF92.5080900@postnewspapers.com.au> (raw)
In-Reply-To: <47F0CB12.5010506@postnewspapers.com.au>
References: <47F09DD1.1080905@sanbi.ac.za>
	<47F0C2A8.9010008@postnewspapers.com.au>
	<47F0CB12.5010506@postnewspapers.com.au>

> -- Find any `a' for which `item_from_a_is_in_b' is
> -- true for all items in `a'
> SELECT a_tid AS is_redundant, b_tid AS contained_by
> FROM (
>   -- For every item in every pair of purchases,
>   -- determine whether the item in purchase `a'
>   -- was also in purchase `b'.
>   SELECT
>     a.tid AS a_tid,
>     b.tid AS b_tid,
>     a.item AS item,
>     EXISTS(
>       -- Was this item from `a' also in the `b' purchase?
>       SELECT 1 FROM togo x WHERE x.tid = b.tid AND x.item = a.item
>     ) AS item_from_a_is_in_b
>   FROM togo a INNER JOIN togo b ON (a.tid <> b.tid)
>   GROUP BY a.tid, b.tid, a.item) AS item_containment
> GROUP BY a_tid, b_tid
> HAVING every(item_from_a_is_in_b);

That really should've been written as:

SELECT
  a.tid AS is_redundant,
  b.tid AS contained_by
FROM togo a INNER JOIN togo b ON (a.tid <> b.tid)
GROUP BY a.tid, b.tid
HAVING
  EVERY(EXISTS(
    SELECT 1 FROM togo x WHERE x.tid = b.tid AND x.item = a.item
  ));

... but I'm a bit of an idiot, and couldn't figure out why the
EVERY(EXISTS(subq)) wasn't working when testing it before.

Sorry for all the noise.

--
Craig Ringer



view thread (5+ messages)

Message-ID: <47F0CF92.5080900@postnewspapers.com.au>
Permalink:  ../47F0CF92.5080900@postnewspapers.com.au/
Also on:    postgresql.org/message-id/47F0CF92.5080900@postnewspapers.com.au

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: craig@postnewspapers.com.au, allank@sanbi.ac.za
  Subject: Re: Removing redundant itemsets
  In-Reply-To: <47F0CF92.5080900@postnewspapers.com.au>

* 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