X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 3F4EB32A23A; Fri, 1 Oct 2004 19:30:31 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 28516-10; Fri, 1 Oct 2004 18:30:12 +0000 (GMT) Received: from solarwind.bpsi.net (solarwind.bpsi.net [209.54.240.1]) by svr1.postgresql.org (Postfix) with ESMTP id 8A086329CDB; Fri, 1 Oct 2004 19:30:10 +0100 (BST) Received: from ra.bpsi.net (ra.bpsi.net [199.199.134.1]) by solarwind.bpsi.net (8.12.8/8.12.8) with ESMTP id i91ISlfu026926; Fri, 1 Oct 2004 13:28:47 -0500 (CDT) Date: Fri, 1 Oct 2004 13:28:47 -0500 (CDT) From: "D. Duccini" X-Sender: duccini@solarwind To: Bruno Wolff III Cc: pgsql-sql@postgresql.org, Pgsql-novice Subject: Re: date_trunc'd timestamp index possible? In-Reply-To: <20041001182830.GA20624@wolff.to> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/12 X-Sequence-Number: 11097 > The reason this doesn't work is that the timestamp to date conversion > depends on the time zone setting. In theory you should be able to avoid > this by specifying the time zone to check the date in. I tried something > like the following which I think should work, but doesn't: > create idxfoo on foo (date(timezone('UTC',footime))); > > The conversion of the timestamp stored in footime should be immutable > and then taking the date should work. I did find that date of a timestamp > without time zone is treated as immutable. > > I am not sure how to check if the supplied function for converting > a timestamp with time zone to a timestamp without timezone using a > specified time zone is immutable. I think this function should be > immutable, but that it probably isn't. I think we found a way around it! CREATE OR REPLACE FUNCTION date_immutable( timestamptz ) RETURNS date AS 'SELECT date( $1 ) ;' LANGUAGE 'sql' IMMUTABLE ; CREATE INDEX "new_event_dt" ON "the_events" USING btree ( date_immutable( "event_dt_tm" ) ) ; ----------------------------------------------------------------------------- david@backpack.com BackPack Software, Inc. www.backpack.com +1 651.645.7550 voice "Life is an Adventure. +1 651.645.9798 fax Don't forget your BackPack!" -----------------------------------------------------------------------------