X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 96864D1C7F2 for ; Wed, 23 Jul 2003 19:48:37 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 56155-03 for ; Wed, 23 Jul 2003 16:47:56 -0300 (ADT) Received: from localhost.localdomain (unknown [65.217.53.66]) by svr1.postgresql.org (Postfix) with ESMTP id A3C2ED1C7F1 for ; Wed, 23 Jul 2003 16:48:35 -0300 (ADT) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.8/8.12.8) with ESMTP id h6NIQfqd024090; Wed, 23 Jul 2003 14:26:41 -0400 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id h6NJmYZ03851; Wed, 23 Jul 2003 15:48:35 -0400 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id 34ADMHP6; Wed, 23 Jul 2003 15:48:33 -0400 Subject: Re: time delay function From: Robert Treat To: Christoph Haller Cc: pgsql-sql@postgresql.org, gbajaj@tietronix.com In-Reply-To: <3F1CF45E.901B6657@rodos.fzk.de> References: <3F1CF45E.901B6657@rodos.fzk.de> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 23 Jul 2003 15:48:34 -0400 Message-Id: <1058989714.22273.688.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/346 X-Sequence-Number: 14460 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