Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llFG5-0008Ck-Cq for pgsql-admin@arkaria.postgresql.org; Mon, 24 May 2021 18:24:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1llFG4-0003Q9-4w for pgsql-admin@arkaria.postgresql.org; Mon, 24 May 2021 18:24:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llFG3-0003Q1-Sa for pgsql-admin@lists.postgresql.org; Mon, 24 May 2021 18:24:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llFFx-00045F-Hw for pgsql-admin@postgresql.org; Mon, 24 May 2021 18:24:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 14OIOl7l1012708; Mon, 24 May 2021 14:24:47 -0400 From: Tom Lane To: Wells Oliver cc: pgsql-admin Subject: Re: Creating an index on a timestamp with time zone cast to a date-- possible? In-reply-to: References: Comments: In-reply-to Wells Oliver message dated "Mon, 24 May 2021 11:19:05 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1012706.1621880687.1@sss.pgh.pa.us> Date: Mon, 24 May 2021 14:24:47 -0400 Message-ID: <1012707.1621880687@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Wells Oliver writes: > Seems you can't do this: > create index on someschema.sometable ((modified_at::date)); > If modified_at is a timestamp with a time zone: > ERROR: functions in index expression must be marked IMMUTABLE > But you can if it's a timestamp without a time zone. Anyway, any way of > casting that as to use it as an index? The problem is that casting a timestamptz to a date (or a timestamp for that matter) depends on your current timezone setting. You could do something like create index on sometable (((modified_at at time zone 'UTC')::date)); regards, tom lane