pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Oleg <serovov@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #5852: Function date_trunc is not IMMUTABLE
Date: Thu, 27 Jan 2011 09:40:04 -0500
Message-ID: <21812.1296139204@sss.pgh.pa.us> (raw)
In-Reply-To: <201101271102.p0RB2kxi071325@wwwmaster.postgresql.org>
References: <201101271102.p0RB2kxi071325@wwwmaster.postgresql.org>

"Oleg" <serovov@gmail.com> writes:
> Please mark function date_trunc as IMMUTABLE for using in index.

The version for timestamp without time zone already is marked immutable.
The version for timestamp with time zone can't be marked immutable,
because it isn't: its behavior depends on the timezone setting.

Depending on what it is you hope to accomplish, you might be able to do
something like this:

regression=# create table t1 (f1 timestamptz);
CREATE TABLE
regression=# create index ii on t1 (date_trunc('day', f1 AT TIME ZONE 'UTC'));
CREATE INDEX

This is immutable because the truncation happens with respect to a fixed
timezone.  (Doesn't have to be UTC, any constant timezone name will do.)

			regards, tom lane



view thread (3+ messages)

Message-ID: <21812.1296139204@sss.pgh.pa.us>
Permalink:  ../21812.1296139204@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/21812.1296139204@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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, serovov@gmail.com
  Subject: Re: BUG #5852: Function date_trunc is not IMMUTABLE
  In-Reply-To: <21812.1296139204@sss.pgh.pa.us>
  References: <201101271102.p0RB2kxi071325@wwwmaster.postgresql.org> <21812.1296139204@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