Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 4381347597B for ; Mon, 19 Aug 2002 03:27:27 -0400 (EDT) Received: from herald.cybage.com (universe.cybage.com [202.54.41.226]) by postgresql.org (Postfix) with ESMTP id 6B2BA47591C for ; Mon, 19 Aug 2002 03:27:23 -0400 (EDT) Received: from Sugandha ([192.168.5.32]) by herald.cybage.com with Microsoft SMTPSVC(5.0.2195.4453); Mon, 19 Aug 2002 12:59:48 +0530 Message-ID: <099401c24752$327ae380$2005a8c0@cybage.com> From: "Sugandha Shah" To: "Richard Huxton" Cc: References: <01b301c24352$12570fb0$2005a8c0@cybage.com> <200208140702.g7E72Cd05129@janning.planwerk6.local> <027601c2438e$3a6304a0$2005a8c0@cybage.com> <200208141434.16778.dev@archonet.com> Subject: Re: Few Queries Date: Mon, 19 Aug 2002 12:59:47 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-OriginalArrivalTime: 19 Aug 2002 07:29:48.0104 (UTC) FILETIME=[3290DC80:01C24752] X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200208/262 X-Sequence-Number: 9108 Hello Richard, I'm really thankful to you. It worked. Somehow I wasn't getting it to work. This line did the trick. set_time := current_date() - (var_history_age_limit::text || '' days '')::interval; Regards, -Sugandha ----- Original Message ----- From: "Richard Huxton" To: "Sugandha Shah" ; "Janning Vygen" Cc: Sent: Wednesday, August 14, 2002 7:04 PM Subject: Re: [SQL] Few Queries On Wednesday 14 Aug 2002 1:29 pm, Sugandha Shah wrote: > Hi , > > No luck . Even with Select Into . Please if any body has faced similar > problem and knows a solution. You don't need select into here - the sample below deletes everything older than one day. You should be able to adapt it to your needs. Your example had a + rather than a - which would delete things in the future, that might have been what you intended, or it might not. The RAISE NOTICE line prints a useful debug value. I like to scatter these around while I'm testing. CREATE FUNCTION del_old_history() RETURNS int4 AS ' DECLARE var_history_age_limit int4; set_time timestamp; BEGIN var_history_age_limit:=1; set_time := current_date() - (var_history_age_limit::text || '' days '')::interval; RAISE NOTICE ''set time = %'',set_time; delete from history where complete_time <= set_time; return var_history_age_limit; END;' LANGUAGE 'plpgsql'; -- Richard Huxton ---------------------------(end of broadcast)--------------------------- TIP 6: Have you searched our list archives? http://archives.postgresql.org