| From: | Robert Treat <xzilla(at)users(dot)sourceforge(dot)net> |
|---|---|
| To: | Christoph Haller <ch(at)rodos(dot)fzk(dot)de> |
| Cc: | pgsql-sql(at)postgresql(dot)org, gbajaj(at)tietronix(dot)com |
| Subject: | Re: time delay function |
| Date: | 2003-07-23 19:48:34 |
| Message-ID: | 1058989714.22273.688.camel@camel |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Robert Treat | 2003-07-23 20:01:53 | Re: obtuse plpgsql function needs |
| Previous Message | greg | 2003-07-23 19:38:47 | Re: obtuse plpgsql function needs |