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

From Tom Lane
Subject Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not
Date
Msg-id 1576665.1688063087@sss.pgh.pa.us
Whole thread Raw
In response to BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not  (PG Bug reporting form <noreply@postgresql.org>)
Responses Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not  (Braiam <braiamp@gmail.com>)
List pgsql-bugs
Braiam <braiamp@gmail.com> writes:
> On Thu, Jun 29, 2023 at 1:52 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> There is no age(date, date) function.  What we have is age(timestamp,
>> timestamp) and age(timestamptz, timestamptz), so the parser has to
>> choose which type to coerce to --- and it prefers timestamptz.

> According to \df+ age both timestamptz and timestamp are immutable:

True, but not very relevant: it's the coercion from date that's
giving you trouble.

> So, whatever type is coerced into pre-function evaluation comes
> with strange results. I'm not aware of a way that I can see what
> kind of type is being coerced into.

EXPLAIN will show that, eg

=# explain verbose select age(current_date, current_date);
                                            QUERY PLAN

---------------------------------------------------------------------------------------------------
 Result  (cost=0.00..0.02 rows=1 width=16)
   Output: age((CURRENT_DATE)::timestamp with time zone, (CURRENT_DATE)::timestamp with time zone)
(2 rows)

            regards, tom lane



pgsql-bugs by date:

Previous
From: Braiam
Date:
Subject: Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not
Next
From: Braiam
Date:
Subject: Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not