pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Creating an index on a timestamp with time zone cast to a date-- possible?
2+ messages / 2 participants
[nested] [flat]

* Creating an index on a timestamp with time zone cast to a date-- possible?
@ 2021-05-24 18:19  Wells Oliver <wells.oliver@gmail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Wells Oliver @ 2021-05-24 18:19 UTC (permalink / raw)
  To: pgsql-admin

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?

-- 
Wells Oliver
wells.oliver@gmail.com <wellsoliver@gmail.com>

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Creating an index on a timestamp with time zone cast to a date-- possible?
@ 2021-05-24 18:24  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Wells Oliver <wells.oliver@gmail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2021-05-24 18:24 UTC (permalink / raw)
  To: Wells Oliver <wells.oliver@gmail.com>; +Cc: pgsql-admin

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2021-05-24 18:24 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-05-24 18:19 Creating an index on a timestamp with time zone cast to a date-- possible? Wells Oliver <wells.oliver@gmail.com>
2021-05-24 18:24 ` Tom Lane <tgl@sss.pgh.pa.us>

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