| From: | Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> |
|---|---|
| To: | Gaurav Singh <gaurav(dot)singh(at)yugabyte(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: postgres_fdw returns wrong rows for age(timestamptz, timestamptz) filters |
| Date: | 2026-10-29 21:40:24 |
| Message-ID: | 5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Fri, 2026-10-30 at 02:30 +0530, Gaurav Singh wrote:
> age(timestamptz, timestamptz) is marked IMMUTABLE, but its result
> depends on the TimeZone setting, because it converts both values to
> local time before subtracting:
>
> SET TimeZone = 'UTC';
> SELECT age('2026-03-01 00:00+00'::timestamptz, '2026-01-31 00:00+00'::timestamptz);
> -- 1 mon 1 day
>
> SET TimeZone = 'America/New_York';
> SELECT age('2026-03-01 00:00+00'::timestamptz, '2026-01-31 00:00+00'::timestamptz);
> -- 29 days
>
> Because of the IMMUTABLE label, postgres_fdw considers age() safe to
> send to the remote server. The remote session runs with
> timezone = 'GMT', so the filter is evaluated in GMT instead of the
> local session's time zone, and the query returns wrong rows.
>
> The mislabel itself was raised recently in the BUG #19644 thread,
> where the concern was that relabeling it STABLE would break existing
> generated columns and indexes.
>
> Would it make sense to mark age(timestamptz, timestamptz) STABLE on
> master, or, if that is too disruptive, to stop postgres_fdw from
> shipping it?
I think that the best solution would be to change the result of the
age() function: if it didn't try to convert to months and just
returned days and smaller, the result should be immutable.
Yours,
Laurenz Albe
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Matt Carter | 2026-10-29 21:52:17 | RE: BUG #19411: libpq 16.x exhibits a memory leak when connections are repeatedly created and destroyed |
| Previous Message | Gaurav Singh | 2026-10-29 21:00:34 | postgres_fdw returns wrong rows for age(timestamptz, timestamptz) filters |