Re: query by partial timestamp

Поиск
Список
Период
Сортировка
От Steve Crawford
Тема Re: query by partial timestamp
Дата
Msg-id 50ECA5DE.3060103@pinpointresearch.com
обсуждение исходный текст
Ответ на query by partial timestamp  (Kirk Wythers <kwythers@umn.edu>)
Список 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 по дате отправления:

Предыдущее
От: Rob Sargent
Дата:
Сообщение: Re: query by partial timestamp
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Discerning when functions had execute revoked from public