pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: bart@lengkeek.net
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17687: Session timezone change does not play well with prepared statements
Date: Mon, 14 Nov 2022 09:20:25 -0500
Message-ID: <888267.1668435625@sss.pgh.pa.us> (raw)
In-Reply-To: <17687-97355f89274fa9a3@postgresql.org>
References: <17687-97355f89274fa9a3@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> 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





view thread (2+ messages)

Message-ID: <888267.1668435625@sss.pgh.pa.us>
Permalink:  ../888267.1668435625@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/888267.1668435625@sss.pgh.pa.us

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, bart@lengkeek.net, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17687: Session timezone change does not play well with prepared statements
  In-Reply-To: <888267.1668435625@sss.pgh.pa.us>

* 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