pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Daniel Verite <daniel@manitou-mail.org>
To: Alban Hertroijs <a.hertroijs@nieuwestroom.nl>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Time zone offset in to_char()
Date: Thu, 11 Jan 2024 19:39:47 +0100
Message-ID: <6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org> (raw)
In-Reply-To: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM>

	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' 
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:
   perform set_config('timezone', tz_, true /* local */); 

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,
-- 
Daniel Vérité
https://postgresql.verite.pro/
Twitter: @DanielVerite





view thread (21+ messages)  latest in thread

Message-ID: <6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org>
Permalink:  ../6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org/
Also on:    postgresql.org/message-id/6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org

 · 

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-general@postgresql.org
  Cc: daniel@manitou-mail.org, a.hertroijs@nieuwestroom.nl
  Subject: Re: Time zone offset in to_char()
  In-Reply-To: <6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org>
  References: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM> <6e77c116-e332-4640-bba5-7a3425a80bad@manitou-mail.org>

* 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