Re: query for records based on date - Mailing list pgsql-sql

From Richard Huxton
Subject Re: query for records based on date
Date
Msg-id 421A4A45.7090309@archonet.com
Whole thread Raw
In response to query for records based on date  ("Brandon Metcalf" <bmetcalf@nortel.com>)
List pgsql-sql
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


pgsql-sql by date:

Previous
From: "Brandon Metcalf"
Date:
Subject: Re: query for records based on date
Next
From: Tom Lane
Date:
Subject: Re: pg primary key bug?