Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dcFCj-00017z-JG for pgsql-admin@arkaria.postgresql.org; Mon, 31 Jul 2017 18:14:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dcFCj-0003I5-5w for pgsql-admin@arkaria.postgresql.org; Mon, 31 Jul 2017 18:14:09 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dcFAx-00005D-1T for pgsql-admin@postgresql.org; Mon, 31 Jul 2017 18:12:19 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dcFAt-0005Qt-Sq for pgsql-admin@postgresql.org; Mon, 31 Jul 2017 18:12:18 +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 v6VICDYp007028; Mon, 31 Jul 2017 14:12:13 -0400 From: Tom Lane To: Mark Steben cc: pgsql-admin Subject: Re: creating index with a cast statement in the predicate In-reply-to: References: Comments: In-reply-to Mark Steben message dated "Mon, 31 Jul 2017 13:33:43 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7026.1501524733.1@sss.pgh.pa.us> Date: Mon, 31 Jul 2017 14:12:13 -0400 Message-ID: <7027.1501524733@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-admin Precedence: bulk Sender: pgsql-admin-owner@postgresql.org Mark Steben writes: > I would like to create an index on a column named value: defined as > varchar(255) > Values in this column can be many, including both dates and non-dates. > The developers run a query that first uses a regular expression to filter > non-dates out > then, ANDS it with the following > *and cast(value as date) >= date_trunc('MONTH', current_date) - interval ' > 2 Month '* > When I attempt to create an index using this statement in the > predicate, I get the error that states that functions in an index predicate > must be marked as Immutable. I think it's unhappy about the varchar-to-date cast. That is not considered immutable because the behavior of date_in() depends on the setting of DateStyle. regards, tom lane -- Sent via pgsql-admin mailing list (pgsql-admin@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-admin