Re: query by partial timestamp - Mailing list pgsql-general

From Steve Crawford
Subject Re: query by partial timestamp
Date
Msg-id 50ECA5DE.3060103@pinpointresearch.com
Whole thread Raw
In response to query by partial timestamp  (Kirk Wythers <kwythers@umn.edu>)
List pgsql-general
On 01/08/2013 02:19 PM, Kirk Wythers wrote:
> I have a column of type TIMESTAMP, I'd like to query all records from 2011. If it were text I could use a partial
suchas: 
>
> WHERE
>     text ~ '2011'
>
> There must be a simple way to pull the year part out of a timestamp format. Thanks in advance.
>
>
>
>
As others pointed out, you can do this with "extract(...).

BUT, if your timestamp column is indexed (and if the index will
constrain your records to a sufficiently small subset of the table that
use of indexes is warranted) you may be better off using date
comparisons. I doubt the planner will use the indexes otherwise.

Cheers,
Steve



pgsql-general by date:

Previous
From: Rob Sargent
Date:
Subject: Re: query by partial timestamp
Next
From: Tom Lane
Date:
Subject: Re: Discerning when functions had execute revoked from public