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 1gYJit-00059F-Hg for pgsql-general@arkaria.postgresql.org; Sat, 15 Dec 2018 23:51:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gYJir-0001EA-S4 for pgsql-general@arkaria.postgresql.org; Sat, 15 Dec 2018 23:51:53 +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 1gYJiq-0001E3-C4 for pgsql-general@lists.postgresql.org; Sat, 15 Dec 2018 23:51:53 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gYJin-0005rH-Gq for pgsql-general@lists.postgresql.org; Sat, 15 Dec 2018 23:51:51 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 185A293B; Sat, 15 Dec 2018 18:51:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sat, 15 Dec 2018 18:51:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm1; bh=g S+dO70V9555CkNWoBXRZ0kGBPmdQQaj0rHkpcySkFM=; b=iGg5KzaXjHPX2nM37 L33j0xUsy5gLOP9H0fPllycXZgOdA8sbEuASN1BdvvwO610OuWRu1R+VM3ib8X+6 27vaDzc0IHYA6V95Ssji1W53s+n9L2gNfjnnHab5T/LiDov9CV0EhFQ9AY98qtq0 lJRFWZuK+a9K2HaO9Or3VRQtDtuBvhOJmcPjHjC7fusIi3O6pgGX0OZJLi2LfpKv W6ztwq8Ox0R4kzJlLBPlZaW1oAgw4yJ8mXb8/Khzz7ocTmXOLC3bRfOAiA3KuIDi 3burhYZPg3PXy5/kOIqu+EEnWduwKL+8+kWGRZNGenqZf09Ykp3kQHIBB/clpiD3 5PxvQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=gS+dO70V9555CkNWoBXRZ0kGBPmdQQaj0rHkpcySk FM=; b=LRlvat4IXJuYPvo609Xcte9GVIuMvjxO7Ka3Lbz14c6osFqXngkrCqGve T7IaRmcBN7coD1uAAnK3+oN5J4qt3CpAQB5IsWVG2krUqbLYltBYlqgNvGtDXDm3 zjQOa3wYOj1VFLG9vzzgYHq30IjTukZJ5+mz37N55yLCijzbS7w0WrjEY+Z+5oYp DFCgG8QBxEHU3fGqH34fFDNR8LLlZ64IDCRPKNkeYQ0/v1XsoEoKsBVK4czHjrMs n7GqCE+IEWg47OZ8PZqJ3sNYkejxX73uc125EAV1bP6OqaCodiiX4uBE/zuWh4ke 7VhjYdwyPi3edu/3fFE3vhOlCOUeA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedtkedrudehjedgudektdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthenuceurghilhhouhhtmecu fedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhepuffvfhfhkf fffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcu oegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucfkphepjedurd dvuddvrddufeegrdefnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhl rghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.3] (unknown [71.212.134.3]) by mail.messagingengine.com (Postfix) with ESMTPA id D2621E4A40; Sat, 15 Dec 2018 18:51:46 -0500 (EST) Subject: Re: date_trunc not immutable To: Ravi Krishna , pgsql-general References: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com> From: Adrian Klaver Message-ID: <2c69c24f-16f6-5253-09dd-39e374d4a69f@aklaver.com> Date: Sat, 15 Dec 2018 15:51:45 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.0 MIME-Version: 1.0 In-Reply-To: <1544916384.3079614.1610261080.7F8C1B97@webmail.messagingengine.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 12/15/18 3:26 PM, Ravi Krishna wrote: > Version: PG 10.6 on AWS Linux. > > I am trying to create an index on function date_trunc('month',timestamp) > > PG is complaining that the function must be marked as IMMUTABLE.  So I > assume that date_trunc is not marked as immutable. > > Definition of immutable from PG documentation > ==================================== > > All functions and operators used in an index definition must be > "immutable", that is, their results must depend only on their arguments > and never on any outside influence (such as the contents of another > table or the current time). This restriction ensures that the behavior > of the index is well-defined. To use a user-defined function in an index > expression or WHERE clause, remember to mark the function immutable when > you create it. > =================================== > What am I missing?  date_trunc will always return the same value for a > given value. Not sure how I can mark a PG function as immutable. No it won't: show timezone; TimeZone ------------ US/Pacific select date_trunc('hour', now()); date_trunc ------------------------ 2018-12-15 15:00:00-08 set timezone='UTC'; select date_trunc('hour', now()); date_trunc ------------------------ 2018-12-15 23:00:00+00 -- Adrian Klaver adrian.klaver@aklaver.com