Transitive Reflexive Closure And Its Discontents
From: David Fetter <david_at_fetter.org>
Date: Wed, 21 Jul 2010 16:11:41 -0500
Message-ID: <3OydnSt9b5UQ_9rRnZ2dnUVZ_v6dnZ2d_at_speakeasy.net>
)
SELECT tail, head, count(*)
FROM t
GROUP BY tail, head;
Date: Wed, 21 Jul 2010 16:11:41 -0500
Message-ID: <3OydnSt9b5UQ_9rRnZ2dnUVZ_v6dnZ2d_at_speakeasy.net>
Folks,
SELECT 1 FROM edges e WHERE e.head = edges.tail
)
UNION ALL
SELECT t1.tail, t1.head, t.chain || t1.head
FROM
edges t1
JOIN
t ON t.head = t1.tail AND t1.tail <> ANY(t.chain) /* No cycles */
)
SELECT tail, head, count(*)
FROM t
GROUP BY tail, head;
Cheers,
David.
-- David Fetter <david_at_fetter.org> http://fetter.org/ Phone: +1 415 235 3778 AIM: dfetter666 Yahoo!: dfetter Skype: davidfetter XMPP: david.fetter_at_gmail.com The only truly new ideas [the right] has come up with in the last twenty years are:(1) supply side economics, which is a way of redistributing the wealth upward toward those who already have more than they know what to do with, and; (2) creationism, which is a parallel idea for redistributing ignorance out from its fundamentalist strongholds to those who know more than they need to. Barbara EhrenreichReceived on Wed Jul 21 2010 - 23:11:41 CEST