Re: query by partial timestamp

From: Michael Nolan <htfoot(at)gmail(dot)com>
To: Gavan Schneider <pg-gts(at)snkmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: query by partial timestamp
Date: 2013-01-09 17:42:02
Message-ID: CAOzAquK1PAXWFu7ViL2R0miDxw=bcP14K4iufA4iufBtS33CXQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/8/13, Gavan Schneider <pg-gts(at)snkmail(dot)com> wrote:

> 2. SELECT ... WHERE
> '2011-01-01'::TIMESTAMP <= col_of_type_timestamp
> AND col_of_type_timestamp <=
> '2011-12-31'::TIMESTAMP;

This won't quite work, because '2011-12-31'::TIMESTAMP
is the same as 2011-12-31 00:00:00.00000
so records timestamped later in the day on the 31st would not get selected

SELECT ... WHERE
'2011-01-01'::TIMESTAMP <= col_of_type_timestamp
AND col_of_type_timestamp < '2012-01:01'::TIMESTAMP;

would get all records with a 2011 timestamp.
--
Mike Nolan

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Michael Nolan 2013-01-09 17:47:59 Re: query by partial timestamp
Previous Message Honza Horak 2013-01-09 17:14:46 PostgreSQL hackfest @ Developer Conference 2013, Brno, CZ