Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TVKKW-00048N-6A for pgsql-sql@postgresql.org; Mon, 05 Nov 2012 10:54:56 +0000 Received: from aleph.wmmi.net ([72.14.190.87] helo=mail.wmmi.net) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TVKKP-0002UM-Lt for pgsql-sql@postgresql.org; Mon, 05 Nov 2012 10:54:55 +0000 Received: from [10.66.1.101] (99-48-204-182.lightspeed.brhmmi.sbcglobal.net [99.48.204.182]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: awilliam) by mail.wmmi.net (Postfix) with ESMTP id 202EF127A5 for ; Mon, 5 Nov 2012 05:54:48 -0500 (EST) Message-ID: <1352112887.4089.1.camel@workstation.wmmi.net> Subject: Re: Date Index From: Adam Tauno Williams Reply-To: awilliam@whitemice.org To: pgsql-sql@postgresql.org Date: Mon, 05 Nov 2012 05:54:47 -0500 In-Reply-To: <20081031074854.GA1015@a-kretschmer.de> References: <001e01c93ad0$ffcbe190$ff63a4b0$@hansen@brightbuilders.com> <20081031074854.GA1015@a-kretschmer.de> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.6.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -4.2 (----) X-Archive-Number: 201211/1 X-Sequence-Number: 36934 On Fri, 2008-10-31 at 08:48 +0100, A. Kretschmer wrote: > 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 I'm attempting to create an index as specified in this [old] thread; but the adapted example fails. OGo=> create index job_date_only on job(extract(date from start_date at time zone 'utc')); ERROR: timestamp units "date" not recognized I assume this is because the data type is 'timestamp with timezone' which differs slightly from the original example. But - select extract(month from start_date) from job; - [for example] works. Is there an equivalent syntax to 'date' for timestamp?