pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: David Loh <david@bizsurf.com>
To: pgsql-sql@postgresql.org
Subject: Re: A minute in timestamp
Date: Thu, 8 May 2003 08:24:03 +0100
Message-ID: <200305080824.04091.dev@archonet.com> (raw)
In-Reply-To: <003501c3152c$b3872a30$f92c2c0a@david>
References: <003501c3152c$b3872a30$f92c2c0a@david>

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




view thread (3+ messages)  latest in thread

Message-ID: <200305080824.04091.dev@archonet.com>
Permalink:  ../200305080824.04091.dev@archonet.com/
Also on:    postgresql.org/message-id/200305080824.04091.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, david@bizsurf.com
  Subject: Re: A minute in timestamp
  In-Reply-To: <200305080824.04091.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox