Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 11CD165B1F9 for ; Tue, 16 Mar 2010 18:09:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 21300-03 for ; Tue, 16 Mar 2010 21:09:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 58917635A15 for ; Tue, 16 Mar 2010 18:09:18 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o2GL9DIe014551; Tue, 16 Mar 2010 17:09:13 -0400 (EDT) To: Tony Cebzanov cc: Richard Huxton , pgsql-sql@postgresql.org Subject: Re: Avoiding cycles in a directed graph In-reply-to: <4B9FEEE8.1060404@andrew.cmu.edu> References: <4B9FDFDE.5030005@andrew.cmu.edu> <4B9FE752.4080709@archonet.com> <14113.1268771643@sss.pgh.pa.us> <4B9FEEE8.1060404@andrew.cmu.edu> Comments: In-reply-to Tony Cebzanov message dated "Tue, 16 Mar 2010 16:49:44 -0400" Date: Tue, 16 Mar 2010 17:09:12 -0400 Message-ID: <14550.1268773752@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.459 tagged_above=-10 required=5 tests=AWL=0.140, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201003/115 X-Sequence-Number: 33822 Tony Cebzanov writes: > I'm okay with running the big, fat WITH RECURSIVE query in my insert > trigger if I have to -- it won't be great for performance, but I don't > expect this to be a frequent operation, so I'll accept the performance > hit if it works. > Unfortunately I can't even get that working. Here's the (not at all > functional) trigger I've got right now, which only detects the cycle > *after* it's been inserted, which is of no help at all. Any way I can > modify this to do the right thing? Run it in an AFTER trigger? If you don't expect this to be common, maybe you could fix the concurrency issue by taking a table-wide lock that locks out other writers. regards, tom lane