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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: braiamp+pg(at)gmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not
Date: 2023-06-29 17:52:42
Message-ID: 1573129.1688061162@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> There's no much difference between timestamp and dateT00:00:00.000, yet
> using age(date, date) for some reason internally doesn't type coerce
> correctly into the appropriated types.

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.
Perhaps this is surprising as an isolated fact, but I believe what
it stems from is that timestamptz is the "preferred" type in this
type category. That's not something that's likely to change.
Then what you have within the expression is a coercion from date
to timestamptz, which depends on the time zone, so it's not
immutable.

Bottom line is that you'd better cast the dates to timestamp
explicitly. Or you could make an age(date, date) wrapper
function that does that.

> I remember that on a previous
> versions (not sure if it was 14) this wasn't the case,

Doubt it. Nothing here has changed in a couple of decades.
Maybe you had a wrapper function that you forgot to bring over?

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Braiam 2023-06-29 18:20:44 Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not
Previous Message David G. Johnston 2023-06-29 17:45:36 Re: BUG #18007: age(timestamp, timestamp) is marked as immutable, but using age(date, date) says it's not