X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1A58252BE8 for ; Thu, 14 Jul 2005 11:29:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03490-07 for ; Thu, 14 Jul 2005 14:29:51 +0000 (GMT) Received: from megazone.bigpanda.com (megazone.bigpanda.com [64.147.171.210]) by svr1.postgresql.org (Postfix) with ESMTP id E90CA52BF9 for ; Thu, 14 Jul 2005 11:29:50 -0300 (ADT) Received: by megazone.bigpanda.com (Postfix, from userid 1001) id B56DA354AD; Thu, 14 Jul 2005 07:29:51 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by megazone.bigpanda.com (Postfix) with ESMTP id B142835429; Thu, 14 Jul 2005 07:29:51 -0700 (PDT) Date: Thu, 14 Jul 2005 07:29:51 -0700 (PDT) From: Stephan Szabo To: =?iso-8859-1?Q?Sebastian_K=FChner?= Cc: pgsql-admin@postgresql.org Subject: Re: LOOP and EXIT In-Reply-To: <00c601c58709$fce8d560$6501a8c0@oper2> Message-ID: <20050714072802.V15619@megazone.bigpanda.com> References: <00c601c58709$fce8d560$6501a8c0@oper2> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200507/99 X-Sequence-Number: 18155 On Tue, 12 Jul 2005, [iso-8859-1] Sebastian K=FChner wrote: > Hello, > > I'm new here in this group... and I hope that I find the solution for my > problem here. > > I wrote a simple function which looks like this: > > CREATE OR REPLACE FUNCTION watchdog() RETURNS TIME AS ' > DECLARE > watchdog_control RECORD; > help RECORD; > BEGIN > LOOP > PERFORM * FROM watchdog_ctl; > > IF NOT FOUND THEN > EXIT; > END IF; > > PERFORM sleep(3); > > END LOOP; > RETURN now(); > END; > ' LANGUAGE plpgsql; > > That means that I want to leave the loop if there isn't an entry in the > table watchdog_ctl. This works fine if the table is empty at the startup = of > the function (select watchdog();). But if I empty the table watchdog_ctl > while the function is running it seems to be an endless loop. Hay anyone = of > you an idea why?? What version are you using? I believe in versions prior to 8.0, that perform is going to see the same snapshot each time, which means it's not going to see the effects of your delete. The function seems to act as you want in 8.1beta (can't test 8.0 right now).