Re: sleep?

Поиск
Список
Период
Сортировка
От John DeSoi
Тема Re: sleep?
Дата
Msg-id D9712202-F287-4CCF-A9C2-EE8A7E11AD83@pgedit.com
обсуждение исходный текст
Ответ на Re: sleep?  (Guido Barosio <gbarosio@gmail.com>)
Ответы Re: sleep?
Список 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.
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;

В списке pgsql-admin по дате отправления:

Предыдущее
От: Bricklen Anderson
Дата:
Сообщение: Re: sleep?
Следующее
От: Sean Chittenden
Дата:
Сообщение: Corrupted data, best course of repair?