X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4012CD6DFB for ; Mon, 22 Aug 2005 10:34:30 -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 57437-04 for ; Mon, 22 Aug 2005 13:34:26 +0000 (GMT) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.207]) by svr1.postgresql.org (Postfix) with ESMTP id 8F2DFD6D71 for ; Mon, 22 Aug 2005 10:34:24 -0300 (ADT) Received: by wproxy.gmail.com with SMTP id i4so969133wra for ; Mon, 22 Aug 2005 06:34:29 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:references; b=qhmIiad6WVSQrEVIz//8dFgZmPFw2iRzxcaxwJmQjWDPf/CFPzlVl/w0artECK3ZX+TPehwQahRpoVvgyqHENB+x3jsE14GEyUzVvltoF5f36IYzhMxxiWh/2kLexhIMvoEwyEHcDKwI0RWQvfS72ChJyq8xzvvVrlryst0y74U= Received: by 10.54.6.50 with SMTP id 50mr1448756wrf; Mon, 22 Aug 2005 06:34:29 -0700 (PDT) Received: by 10.54.94.11 with HTTP; Mon, 22 Aug 2005 06:34:29 -0700 (PDT) Message-ID: <6c21003b05082206341411de2d@mail.gmail.com> Date: Mon, 22 Aug 2005 08:34:29 -0500 From: Don Drake To: John DeSoi Subject: Re: sleep? Cc: Guido Barosio , pgsql-admin@postgresql.org In-Reply-To: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_22141_28617610.1124717669284" References: <6c21003b050821122278e3d7d5@mail.gmail.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.087 required=5 tests=[AWL=-0.033, HTML_50_60=0.095, HTML_MESSAGE=0.001, RCVD_BY_IP=0.024] X-Spam-Level: X-Archive-Number: 200508/259 X-Sequence-Number: 18578 ------=_Part_22141_28617610.1124717669284 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for all of the replies. I recompiled my DB with plperlu and am using= =20 perl's sleep function. I agree that a basic function (non-CPU intensive sleep) like this should be= =20 built in. Thanks again. -Don On 8/21/05, John DeSoi wrote: >=20 >=20 > On Aug 21, 2005, at 5:09 PM, Guido Barosio wrote: >=20 > > 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. >=20 >=20 > 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. >=20 >=20 > John DeSoi, Ph.D. > http://pgedit.com/ > Power Tools for PostgreSQL >=20 >=20 >=20 > create or replace function sleep (integer) returns time as ' > declare > seconds alias for $1; > later time; > thetime time; > begin > thetime :=3D timeofday()::timestamp; > later :=3D thetime + (seconds::text || '' seconds'')::interval; > loop > if thetime >=3D later then > exit; > else > thetime :=3D timeofday()::timestamp; > end if; > end loop; >=20 > return later; > end; > ' language plpgsql; >=20 --=20 Donald Drake President Drake Consulting http://www.drakeconsult.com/ http://www.MailLaunder.com/ http://www.mobilemeridian.com/ 312-560-1574 ------=_Part_22141_28617610.1124717669284 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Thanks for all of the replies.  I recompiled my DB with plperlu and am= using perl's sleep function.

I agree that a basic function (non-CPU intensive sleep) like this should be= built in.

Thanks again.

-Don


On 8/21/05, John DeSoi <desoi@pgedit= .com> wrote:

On Aug 21, 2005, at 5:09 PM, Guido Barosio wrote:

> Don't kno= w about such thing, but I guess that a plpgsql function
> could help = using datetime var's.
>
> Just a guess, don't know if the optim= al solution.


Yes, you can write one in plpgsql using timeofday, but it is ho= rribly
inefficient wastes CPU cycles busy looping. I use the version bel= ow
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 '
&nb= sp;    declare
       =   seconds alias for $1;
       &= nbsp; later time;
         theti= me time;
     begin
     = ;    thetime :=3D timeofday()::timestamp;
         later :=3D thetime + (= seconds::text || '' seconds'')::interval;
     =     loop
        =      if thetime >=3D later then
   = ;            &n= bsp; exit;
          &= nbsp;  else
         &= nbsp;       thetime :=3D timeofday()::timestamp;
      = ;       end if;
    &n= bsp;    end loop;

      = ;   return later;
     end;
' language = plpgsql;



--
Donald Drak= e
President
Drake Consulting
http://www= .drakeconsult.com/
http://ww= w.MailLaunder.com/
http:/= /www.mobilemeridian.com/
312-560-1574
------=_Part_22141_28617610.1124717669284--