Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYKH2-0006YI-2W for pgsql-general@arkaria.postgresql.org; Sun, 16 Dec 2018 00:27:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYKGz-0007jb-R5 for pgsql-general@arkaria.postgresql.org; Sun, 16 Dec 2018 00:27:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYKGz-0007jU-FO for pgsql-general@lists.postgresql.org; Sun, 16 Dec 2018 00:27:09 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYKGw-0006aR-Dl for pgsql-general@lists.postgresql.org; Sun, 16 Dec 2018 00:27:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wBG0R3KU007870; Sat, 15 Dec 2018 19:27:03 -0500 From: Tom Lane To: Ravi Krishna cc: "pgsql-general" Subject: Re: date_trunc not immutable In-reply-to: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com> References: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com> Comments: In-reply-to Ravi Krishna message dated "Sat, 15 Dec 2018 18:26:24 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7868.1544920023.1@sss.pgh.pa.us> Date: Sat, 15 Dec 2018 19:27:03 -0500 Message-ID: <7869.1544920023@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ravi Krishna writes: > I am trying to create an index on function date_trunc('month',timestamp) > PG is complaining that the function must be marked as IMMUTABLE. The timestamptz version of it is not immutable, because its effects depend on the timezone setting: regression=# set timezone = 'America/New_York'; SET regression=# select date_trunc('month', now()); date_trunc ------------------------ 2018-12-01 00:00:00-05 (1 row) regression=# set timezone = 'Europe/Paris'; SET regression=# select date_trunc('month', now()); date_trunc ------------------------ 2018-12-01 00:00:00+01 (1 row) If you want immutability, you need to be working with timestamp-without-tz or date input, so that timezone isn't a factor. regards, tom lane