Re: Why *exactly* is date_trunc() not immutable ? - Mailing list pgsql-general

From Tom Lane
Subject Re: Why *exactly* is date_trunc() not immutable ?
Date
Msg-id 9690.1171898720@sss.pgh.pa.us
Whole thread Raw
In response to Re: Why *exactly* is date_trunc() not immutable ?  (Alban Hertroys <alban@magproductions.nl>)
List pgsql-general
Alban Hertroys <alban@magproductions.nl> writes:
> What I'm trying to say is not that it _is_ immutable, but that it
> _behaves_ immutable (under said conditions).
> This could imply that if a certain condition is available in a query on
> which such a function operates, it would behave immutable.

Right, but we don't have any way to represent such a fact in
date_trunc's pg_proc entry, so we have to mark it as "not immutable".

There was a related discussion awhile ago when designing the current
set of "what time is it" functions --- transaction_timestamp(),
statement_timestamp(), and clock_timestamp().  The original proposal
had just a single function that took a parameter telling which value
you wanted.  The trouble with that was that it'd have had to be marked
volatile, thereby defeating any ability to optimize conditions using it.
By splitting into three functions, we were able to limit the "volatile"
label to clock_timestamp().

            regards, tom lane

pgsql-general by date:

Previous
From: Jerry LeVan
Date:
Subject: Re: Synchronize tables question....
Next
From: "David Legault"
Date:
Subject: Per Database Roles