pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: Gaurav Singh <gaurav.singh@yugabyte.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: postgres_fdw returns wrong rows for age(timestamptz, timestamptz) filters
Date: Thu, 29 Oct 2026 22:40:24 +0100
Message-ID: <5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at> (raw)
In-Reply-To: <CAEcQ1badDTrQM8qjdkMOy4Bs5xP2EwKopK=3O_-DSatkrsz2KA@mail.gmail.com>
References: <CAEcQ1badDTrQM8qjdkMOy4Bs5xP2EwKopK=3O_-DSatkrsz2KA@mail.gmail.com>

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






view thread (5+ messages)  latest in thread

Message-ID: <5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at>
Permalink:  ../5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at/
Also on:    postgresql.org/message-id/5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: laurenz.albe@cybertec.at, gaurav.singh@yugabyte.com
  Subject: Re: postgres_fdw returns wrong rows for age(timestamptz, timestamptz) filters
  In-Reply-To: <5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at>
  References: <CAEcQ1badDTrQM8qjdkMOy4Bs5xP2EwKopK=3O_-DSatkrsz2KA@mail.gmail.com> <5c53c98046b8e273dfadaba5bfd92f8e36728bc9.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox