Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLTSL-00F0o4-TU for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Dec 2024 20:37:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tLTSJ-002ElF-4x for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Dec 2024 20:37:12 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLTSI-002El7-S4 for pgsql-bugs@lists.postgresql.org; Wed, 11 Dec 2024 20:37:12 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tLTSH-002L5Q-Av for pgsql-bugs@lists.postgresql.org; Wed, 11 Dec 2024 20:37:11 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4BBKb8C0521766; Wed, 11 Dec 2024 15:37:08 -0500 From: Tom Lane To: Aleksander Alekseev cc: Michael Paquier , pgsql-bugs@lists.postgresql.org Subject: Re: TimestampTz->Text->TimestampTz casting fails with DateStyle 'Postgres' In-reply-to: <394372.1733884998@sss.pgh.pa.us> References: <3416600.1730987836@sss.pgh.pa.us> <4167039.1733796752@sss.pgh.pa.us> <394372.1733884998@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Tue, 10 Dec 2024 21:43:18 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <521764.1733949428.1@sss.pgh.pa.us> Date: Wed, 11 Dec 2024 15:37:08 -0500 Message-ID: <521765.1733949428@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk I wrote: > As I set it up here, we first check the timezone abbreviation list, > then look into the session timezone to see if it has an entry. > I don't expect that this lookup will succeed for anything except LMT, > because every other abbreviation that TZDB knows about is already > listed in our standard abbreviation list. But in the future we > could imagine removing entries from the abbreviation list so that > this code path takes more of the burden. I had a second thought here. The original problem is not really restricted to "LMT", though that case tends to give an obvious "no such timezone abbreviation" failure. There is a more insidious possibility that the cast-back-and-forth succeeds but yields a changed timestamp value, because the abbreviation emitted by timestamptz_out is recognized but interpreted differently by timestamptz_in. I believe that that's at least theoretically possible today, because what timestamptz_out prints for the abbreviation comes out of the prevailing zone's TZDB entry, but what timestamptz_in consults is the timezone_abbreviations list. If our list is out of sync with TZDB, even for just part of the history of a zone, we've got problems. It may well be that there are no live problems today, especially since TZDB has gotten rid of a lot of abbreviations that they decided were made-up rather than in real-world usage. I don't feel like that's a great bet though, and even if it's true today it might not be in the future. So that leads me to wonder if we should flip the lookup order and consult the prevailing zone's TZDB entry first, falling back to timezone_abbreviations only if the abbrev is not known in the current zone. There are certainly reasons not to do that, one being that there would be no way to override TZDB's opinion if you don't like it. And I'd not propose it for back-patch. But it's something to consider. regards, tom lane