Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not

Christophe Pettus <xof@thebuild.com>

From: Christophe Pettus <xof@thebuild.com>
To: Braiam <braiamp@gmail.com>
Cc: Tom Lane <tgl@sss.pgh.pa.us>, braiamp+pg@gmail.com, pgsql-bugs@lists.postgresql.org
Date: 2023-06-29T19:25:49Z
Lists: pgsql-bugs

> On Jun 29, 2023, at 11:29, Braiam <braiamp@gmail.com> wrote:
> Function age(timestamp with time zone, timestamp with time zone) is
> marked as immutable. Postgres shouldn't complain about it.

It's not the age() function as such that is the problem, but the (stable) cast from date to timestamptz.  Stable or volatile inputs to an immutable function make the expression result non-immutable.

For example, abs() is marked as immutable, but you can't do this:

xof=# CREATE TABLE t (i integer);
CREATE TABLE
xof=# CREATE INDEX ON t((abs(random()+i)));
ERROR:  functions in index expression must be marked IMMUTABLE