From: Richard Huxton <dev@archonet.com>
To: Brandon Metcalf <bmetcalf@nortel.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: query for records based on date
Date: Mon, 21 Feb 2005 20:53:25 +0000
Message-ID: <421A4A45.7090309@archonet.com> (raw)
In-Reply-To: <Pine.LNX.4.58L.0502211356580.24449@cash.rhiamet.com>
References: <Pine.LNX.4.58L.0502211356580.24449@cash.rhiamet.com>
Brandon Metcalf wrote:
> If I have a table with an attribute of type "timestamp without time
> zone", what is the best way to query that table for records that are
> older than, say, one week.
>
> I suppose I could get the current time in epoch seconds and the time of
> the attribute in the same, and select those records where the difference
> is greater than the number of seconds in a week. Is there something
> easier like
>
> SELECT * FROM table WHERE attribute IS OLDER THAN one week;
Look up "intervals" in the manuals - you can just subtract timestamps/dates.
Probably also worth searching the mailing lists for "ago()" and
"volatile" to learn about the issues with indexing.
--
Richard Huxton
Archonet Ltd
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, bmetcalf@nortel.com
Subject: Re: query for records based on date
In-Reply-To: <421A4A45.7090309@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