From: | Richard Huxton <dev(at)archonet(dot)com> |
---|---|
To: | "David Loh" <david(at)bizsurf(dot)com>, <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: A minute in timestamp |
Date: | 2003-05-08 07:24:03 |
Message-ID: | 200305080824.04091.dev@archonet.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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 := 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) ?
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()
functions you get in most systems. I find them clearer now I've got used to
them.
--
Richard Huxton
From | Date | Subject | |
---|---|---|---|
Next Message | Victor Yegorov | 2003-05-08 07:50:14 | Re: A minute in timestamp |
Previous Message | David Loh | 2003-05-08 06:40:22 | A minute in timestamp |