Skip site navigation (1) Skip section navigation (2)

Re: sleep?

From: John DeSoi <desoi(at)pgedit(dot)com>
To: Guido Barosio <gbarosio(at)gmail(dot)com>
Cc: Don Drake <dondrake(at)gmail(dot)com>, pgsql-admin(at)postgresql(dot)org
Subject: Re: sleep?
Date: 2005-08-22 01:43:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-admin
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.
Power Tools for PostgreSQL

create or replace function sleep (integer) returns time as '
         seconds alias for $1;
         later time;
         thetime time;
         thetime := timeofday()::timestamp;
         later := thetime + (seconds::text || '' seconds'')::interval;
             if thetime >= later then
                 thetime := timeofday()::timestamp;
             end if;
         end loop;

         return later;
' language plpgsql;

In response to

  • Re: sleep? at 2005-08-21 21:09:49 from Guido Barosio


  • Re: sleep? at 2005-08-22 13:34:29 from Don Drake

pgsql-admin by date

Next:From: Sean ChittendenDate: 2005-08-22 06:51:49
Subject: Corrupted data, best course of repair?
Previous:From: Michael SchmidtDate: 2005-08-22 00:43:33
Subject: Numerical variables in pqsql statements

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group