Re: Date Index

From: "A(dot) Kretschmer" <andreas(dot)kretschmer(at)schollglas(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Date Index
Date: 2008-10-31 07:48:54
Message-ID: 20081031074854.GA1015@a-kretschmer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

am Thu, dem 30.10.2008, um 14:49:16 -0600 mailte Ryan Hansen folgendes:
> Hey all,
>
>
>
> I?m apparently too lazy to figure this out on my own so maybe one of you can
> just make it easy on me. J
>
>
>
> I want to index a timestamp field but I only want the index to include the
> yyyy-mm-dd portion of the date, not the time. I figure this would be where the
> ?expression? portion of the CREATE INDEX syntax would come in, but I?m not sure
> I understand what the syntax would be for this.
>
>
>
> Any suggestions?

Sure.

You can create an index based on a function, but only if the function is
immutable:

test=# create table foo (ts timestamptz);
CREATE TABLE
test=*# create index idx_foo on foo(extract(date from ts));
ERROR: functions in index expression must be marked IMMUTABLE

To solve this problem specify the timezone:

For the same table as above:
test=*# create index idx_foo on foo(extract(date from ts at time zone 'cet'));
CREATE INDEX

If you have a timestamp whitout timezone it is much easier:
test=# create table foo (ts timestamp);
CREATE TABLE
test=*# create index idx_foo on foo(extract(date from ts));
CREATE INDEX

Hope thats help, Andreas
--
Andreas Kretschmer
Kontakt: Heynitz: 035242/47150, D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID: 0x3FFF606C, privat 0x7F4584DA http://wwwkeys.de.pgp.net

In response to

  • Date Index at 2008-10-30 20:49:16 from Ryan Hansen

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Pascal Tufenkji 2008-10-31 09:26:12 Re: Subqueries
Previous Message Scott Marlowe 2008-10-30 21:06:15 Re: Date Index