pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
LOOP and EXIT
2+ messages / 2 participants
[nested] [flat]

* LOOP and EXIT
@ 2005-07-12 17:49  Sebastian Kühner <support@veraza.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Sebastian Kühner @ 2005-07-12 17:49 UTC (permalink / raw)
  To: pgsql-admin

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??

Many thanks!

Sebastian





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: LOOP and EXIT
@ 2005-07-14 14:29  Stephan Szabo <sszabo@megazone.bigpanda.com>
  parent: Sebastian Kühner <support@veraza.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Stephan Szabo @ 2005-07-14 14:29 UTC (permalink / raw)
  To: Sebastian Kühner <support@veraza.com>; +Cc: pgsql-admin

On Tue, 12 Jul 2005, [iso-8859-1] Sebastian Kühner 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).




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2005-07-14 14:29 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-12 17:49 LOOP and EXIT Sebastian Kühner <support@veraza.com>
2005-07-14 14:29 ` Stephan Szabo <sszabo@megazone.bigpanda.com>

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