pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Wells Oliver <wells.oliver@gmail.com>
Cc: pgsql-admin <pgsql-admin@postgresql.org>
Subject: Re: Creating an index on a timestamp with time zone cast to a date-- possible?
Date: Mon, 24 May 2021 14:24:47 -0400
Message-ID: <1012707.1621880687@sss.pgh.pa.us> (raw)
In-Reply-To: <CAOC+FBX+0=rvSsVRA8=PZAc9ccDq--c5OUiQ0WNxGzGgxh_-eA@mail.gmail.com>
References: <CAOC+FBX+0=rvSsVRA8=PZAc9ccDq--c5OUiQ0WNxGzGgxh_-eA@mail.gmail.com>

Wells Oliver <wells.oliver@gmail.com> 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





view thread (2+ messages)

Message-ID: <1012707.1621880687@sss.pgh.pa.us>
Permalink:  ../1012707.1621880687@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1012707.1621880687@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: tgl@sss.pgh.pa.us, wells.oliver@gmail.com
  Subject: Re: Creating an index on a timestamp with time zone cast to a date-- possible?
  In-Reply-To: <1012707.1621880687@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox