Re: First day of month, last day of month

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Fernando Hevia" <fhevia(at)ip-tel(dot)com(dot)ar>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: First day of month, last day of month
Date: 2008-04-24 15:44:44
Message-ID: dcc563d10804240844i67e12e81l2a5f733b746ab207@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Apr 24, 2008 at 9:16 AM, Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com> wrote:
> On Thu, Apr 24, 2008 at 9:10 AM, Fernando Hevia <fhevia(at)ip-tel(dot)com(dot)ar> wrote:
> > > De: pgsql-sql-owner(at)postgresql(dot)org
> > > [mailto:pgsql-sql-owner(at)postgresql(dot)org] En nombre de Scott Marlowe
> >
> > >
> > > Then you can just use date_trunc on the values in the
> > > database. Plus if you're using timestamp WITHOUT timezone,
> > > you can index on it.
> > >
> >
> > Did not understand this. Are you saying timestamps WITH timezone are NOT
> > indexable or you mean that you cant build a partial index on a
> > timestamp-with-time-zone returning function?
>
> Correct, timestamptz or timestamp with timezone (timestamptz is the
> shorter alias) are not indexable because functions in an index must be
> immutable, and date_trunc on a timestamptz is not.

Note that if you are storing your time stamp as timestamptz, you can
use the "at time zone 'xyz'" construct to create an index, and as long
as you retrieve them with the same construct you'll get to use the
index.

create index test_ts_month_trunc on testtable (date_trunc('month',(ts
at time zone 'MST')));
select * from testtable where date_trunc('month',(ts at time zone
'MST'))='2007-10-01 00:00:00'::timestamp;

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Fernando Hevia 2008-04-24 16:07:19 Re: First day of month, last day of month
Previous Message TJ O'Donnell 2008-04-24 15:43:17 Re: How I can check a substring is a valid number in postgresql ?