Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ouaK9-0005TE-LU for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Nov 2022 14:20:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ouaK8-0000Nq-Fj for pgsql-bugs@arkaria.postgresql.org; Mon, 14 Nov 2022 14:20:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ouaK8-0000Nh-6z for pgsql-bugs@lists.postgresql.org; Mon, 14 Nov 2022 14:20:32 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ouaK4-000703-Rv for pgsql-bugs@lists.postgresql.org; Mon, 14 Nov 2022 14:20:31 +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 2AEEKPaQ888268; Mon, 14 Nov 2022 09:20:25 -0500 From: Tom Lane To: bart@lengkeek.net cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #17687: Session timezone change does not play well with prepared statements In-reply-to: <17687-97355f89274fa9a3@postgresql.org> References: <17687-97355f89274fa9a3@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Mon, 14 Nov 2022 07:20:57 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <888266.1668435625.1@sss.pgh.pa.us> Date: Mon, 14 Nov 2022 09:20:25 -0500 Message-ID: <888267.1668435625@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > When a statement is prepared using one session timezone and executed using > another, it returns the wrong timestamp. > Example using psql: > postgres=# SET TIMEZONE TO 'Europe/Berlin'; > SET > postgres=# PREPARE test AS > SELECT '2021-03-15 14:10:03'::timestamptz; > PREPARE > postgres=# SET TIMEZONE TO 'America/Chicago'; > SET > postgres=# EXECUTE test; > timestamptz > ------------------------ > 2021-03-15 08:10:03-05 > (1 row) That is not a bug, it's just how timestamptz works. You'd get the same behavior if you stored the value into a table and then read it out under another timezone setting. (Internally, the reason is that the timestamptz literal is reduced to a Const on sight, and stored that way in the prepared statement.) regards, tom lane