From: John DeSoi <desoi@pgedit.com>
To: Guido Barosio <gbarosio@gmail.com>
Cc: Don Drake <dondrake@gmail.com>
Cc: pgsql-admin@postgresql.org
Subject: Re: sleep?
Date: Sun, 21 Aug 2005 21:43:55 -0400
Message-ID: <D9712202-F287-4CCF-A9C2-EE8A7E11AD83@pgedit.com> (raw)
In-Reply-To: <f7f6b4c705082114094f41bff7@mail.gmail.com>
References: <6c21003b050821122278e3d7d5@mail.gmail.com>
<f7f6b4c705082114094f41bff7@mail.gmail.com>
On Aug 21, 2005, at 5:09 PM, Guido Barosio wrote:
> Don't know about such thing, but I guess that a plpgsql function
> could help using datetime var's.
>
> Just a guess, don't know if the optimal solution.
Yes, you can write one in plpgsql using timeofday, but it is horribly
inefficient wastes CPU cycles busy looping. I use the version below
for some simple testing, but it is not useful for a production
system. It would be nice to have a sleep function that does not
require anything beyond plpgsql.
John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL
create or replace function sleep (integer) returns time as '
declare
seconds alias for $1;
later time;
thetime time;
begin
thetime := timeofday()::timestamp;
later := thetime + (seconds::text || '' seconds'')::interval;
loop
if thetime >= later then
exit;
else
thetime := timeofday()::timestamp;
end if;
end loop;
return later;
end;
' language plpgsql;
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-admin@postgresql.org
Cc: desoi@pgedit.com, gbarosio@gmail.com, dondrake@gmail.com
Subject: Re: sleep?
In-Reply-To: <D9712202-F287-4CCF-A9C2-EE8A7E11AD83@pgedit.com>
References: <6c21003b050821122278e3d7d5@mail.gmail.com> <f7f6b4c705082114094f41bff7@mail.gmail.com> <D9712202-F287-4CCF-A9C2-EE8A7E11AD83@pgedit.com>
* 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