Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id BC3781337BA6 for ; Thu, 27 Jan 2011 10:40:12 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 99473-05 for ; Thu, 27 Jan 2011 14:40:07 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 33E5C1337BA4 for ; Thu, 27 Jan 2011 10:40:05 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p0REe4VS021813; Thu, 27 Jan 2011 09:40:05 -0500 (EST) To: "Oleg" cc: pgsql-bugs@postgresql.org Subject: Re: BUG #5852: Function date_trunc is not IMMUTABLE In-reply-to: <201101271102.p0RB2kxi071325@wwwmaster.postgresql.org> References: <201101271102.p0RB2kxi071325@wwwmaster.postgresql.org> Comments: In-reply-to "Oleg" message dated "Thu, 27 Jan 2011 11:02:46 +0000" Date: Thu, 27 Jan 2011 09:40:04 -0500 Message-ID: <21812.1296139204@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201101/228 X-Sequence-Number: 29250 "Oleg" writes: > Please mark function date_trunc as IMMUTABLE for using in index. The version for timestamp without time zone already is marked immutable. The version for timestamp with time zone can't be marked immutable, because it isn't: its behavior depends on the timezone setting. Depending on what it is you hope to accomplish, you might be able to do something like this: regression=# create table t1 (f1 timestamptz); CREATE TABLE regression=# create index ii on t1 (date_trunc('day', f1 AT TIME ZONE 'UTC')); CREATE INDEX This is immutable because the truncation happens with respect to a fixed timezone. (Doesn't have to be UTC, any constant timezone name will do.) regards, tom lane