Re: time delay function - Mailing list pgsql-sql

From Robert Treat
Subject Re: time delay function
Date
Msg-id 1058989714.22273.688.camel@camel
Whole thread Raw
In response to Re: time delay function  (Christoph Haller <ch@rodos.fzk.de>)
List pgsql-sql
On Tue, 2003-07-22 at 04:22, Christoph Haller wrote:
> >
> > Pseudo code:
> >
> > begin trans
> > select * from table1
> > WAIT FOR 20 SECS
> > update table1 set blah = 'blah'
> > end transcation
> >
> > In pgplsql, Im looking for something like a function that I can use to
> make the process to wait for 20 secs before con
> tinuing to execute the next sql statment?
> >
> AFAIK there is no such thing.
> But probably you can write a C function,
> which waits for N seconds and which can
> be called by your plpgsql function.
> Regards, Christoph
> 

seems like this would work:
21343=# create or replace function wait(integer) returns bool as '
21343'# declare
21343'#         ahora   timestamptz;
21343'#         delay   alias for $1;
21343'#         go      timestamptz;
21343'# begin
21343'#         select now() + (delay || ''seconds'')::interval into go;
21343'# 
21343'#         loop
21343'#         select timeofday() into ahora;
21343'#         exit when ahora > go;
21343'#         end loop;
21343'# 
21343'#         return true;
21343'# end;
21343'# ' language 'plpgsql';
CREATE
21343=# 
21343=# select now(); select wait(5); select now();             now              
-------------------------------2003-07-23 15:45:46.754845-04
(1 row)
wait 
------t
(1 row)
             now              
-------------------------------2003-07-23 15:45:51.758621-04
(1 row)

21343=# 
21343=# select now(); select wait(10); select now();             now              
-------------------------------2003-07-23 15:45:58.713646-04
(1 row)
wait 
------t
(1 row)
            now              
------------------------------2003-07-23 15:46:08.71887-04
(1 row)



Robert Treat
-- 
Build A Brighter Lamp :: Linux Apache {middleware} PostgreSQL



pgsql-sql by date:

Previous
From: greg@turnstep.com
Date:
Subject: Re: obtuse plpgsql function needs
Next
From: Robert Treat
Date:
Subject: Re: obtuse plpgsql function needs