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 1rNzyC-000ID7-12 for pgsql-general@arkaria.postgresql.org; Thu, 11 Jan 2024 18:40:00 +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 1rNzyA-00E1J7-86 for pgsql-general@arkaria.postgresql.org; Thu, 11 Jan 2024 18:39:58 +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 1rNzy9-00E1Iz-TZ for pgsql-general@lists.postgresql.org; Thu, 11 Jan 2024 18:39:57 +0000 Received: from mail.verite.pro ([185.16.44.216]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rNzy5-0013ej-Be for pgsql-general@lists.postgresql.org; Thu, 11 Jan 2024 18:39:57 +0000 Received: by mail.verite.pro (Postfix, from userid 1000) id B4DC48C01A3; Thu, 11 Jan 2024 19:39:51 +0100 (CET) Content-Type: text/plain; charset="utf-8" Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 From: "Daniel Verite" Subject: Re: Time zone offset in to_char() To: "Alban Hertroijs" Cc: "pgsql-general@lists.postgresql.org" In-Reply-To: Date: Thu, 11 Jan 2024 19:39:47 +0100 Message-Id: <6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org> X-Mailer: Manitou v1.7.3 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alban Hertroijs wrote: > 1). The first function has as a drawback that it changes the time zone for > the entire transaction (not sufficiently isolated to my tastes) But if you add in the function declaration SET timezone TO 'Europe/Amsterdam'=20 like in your 2nd function, or simply SET timezone FROM CURRENT doesn't that solve this problem? Because as the doc says If a SET clause is attached to a function, then the effects of a SET LOCAL command executed inside the function for the same variable are restricted to the function: the configuration parameter's prior value is still restored at function exit The actual value to which the timezone is set through this statement does not matter, as the first instruction in the function overwrites it: =E2=80=82=E2=80=82=E2=80=82perform set_config('timezone', tz_, true /* loca= l */);=20 The point is that the prior value of timezone being restored automatically at function exit, the temporary setting will not leak out of the function. Best regards, --=20 Daniel V=C3=A9rit=C3=A9 https://postgresql.verite.pro/ Twitter: @DanielVerite