X-Original-To: pgsql-sql@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AF1C147630B for ; Thu, 8 May 2003 03:24:11 -0400 (EDT) Received: from anchor-post-35.mail.demon.net (anchor-post-35.mail.demon.net [194.217.242.85]) by postgresql.org (Postfix) with ESMTP id 9EC4F475B8E for ; Thu, 8 May 2003 03:24:10 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-35.mail.demon.net with esmtp (Exim 3.36 #2) id 19Dfl9-0005OW-0Z; Thu, 08 May 2003 08:24:07 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 5860F176B6; Thu, 8 May 2003 08:24:06 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id B4EC81678A; Thu, 8 May 2003 08:24:05 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: "David Loh" , Subject: Re: A minute in timestamp Date: Thu, 8 May 2003 08:24:03 +0100 User-Agent: KMail/1.4.3 References: <003501c3152c$b3872a30$f92c2c0a@david> In-Reply-To: <003501c3152c$b3872a30$f92c2c0a@david> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200305080824.04091.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Spam-Status: No, hits=-38.9 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200305/159 X-Sequence-Number: 13324 On Thursday 08 May 2003 7:40 am, David Loh wrote: > Hi all. > After some read of postgres' documentations, I can't found any command > perform similar task like timediff() in other SQL server, the only thing I > got is date_part(). For my case, what I actually need is to create a > trigger (before insert) that check previous record (1 mins), grab the > previous value and deduct new value (NEW.myValue :=3D Previous.myValue - > NEW.myOtherValue), and since the records are insert every minutes,the > function should trace back to the record entered a minute ago (for e.g, > 12:38 will check for record of 12:37 and grab the value), hence timestamp > even include the milli-second, is there any command/trick to check if the > record are entered approximately 55-65 secs (1 minutes +/- 5 secs) ?=20 Do exactly as you've just described: SELECT .... WHERE t BETWEEN now()-'1 min 5 secs'::interval AND now()-'55 secs'::interval It takes a while to get used to PG's date/time/interval types vs timediff()= =20 functions you get in most systems. I find them clearer now I've got used to= =20 them. --=20 Richard Huxton