pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Alban Hertroys <haramrae@gmail.com>
Cc: Alban Hertroys <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 13:09:00 -0800
Message-ID: <5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com> (raw)
In-Reply-To: <752055E6-31DA-404F-AB5E-0BAB83836108@gmail.com>
References: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM>
	<11b56239-9f18-4b94-aeac-395648a2bfe3@aklaver.com>
	<752055E6-31DA-404F-AB5E-0BAB83836108@gmail.com>

On 1/11/24 11:04, Alban Hertroys wrote:
> 

> 
> I didn’t succeed in calling SET LOCAL TIMEZONE from within the function. Could be I missed something, then Google (stackoverflow) pointed me to set_config().

CREATE OR REPLACE FUNCTION public.tz_fnc()
  RETURNS void
  LANGUAGE plpgsql
AS $function$
BEGIN
     SET LOCAL  TIMEZONE = 'UTC';
     RAISE NOTICE '%', to_char(now(), 'OF');
END;
$function$


test=# begin ;
BEGIN
test=*# select public.tz_fnc();
NOTICE:  +00
  tz_fnc
--------

(1 row)

test=*# show timezone;
  TimeZone
----------
  UTC
(1 row)

test=*# commit;
COMMIT
test=# show timezone;
       TimeZone
---------------------
  America/Los_Angeles
(1 row)





> 
> I did manage to apply it to the second function header, which I think behaves such that the time zone change stays within function scope. Right now I’m not 100% sure that I verified that. More to check tomorrow.
> 
> Frankly, I do hope that you’re right here, that would make my work easier.
> 
> Alban Hertroys
> --
> If you can't see the forest for the trees,
> cut the trees and you'll find there is no forest.
> 

-- 
Adrian Klaver
adrian.klaver@aklaver.com






view thread (21+ messages)  latest in thread

Message-ID: <5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com>
Permalink:  ../5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com/
Also on:    postgresql.org/message-id/5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com

 · 

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: adrian.klaver@aklaver.com, haramrae@gmail.com, a.hertroijs@nieuwestroom.nl
  Subject: Re: Time zone offset in to_char()
  In-Reply-To: <5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com>
  References: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM> <11b56239-9f18-4b94-aeac-395648a2bfe3@aklaver.com> <752055E6-31DA-404F-AB5E-0BAB83836108@gmail.com> <5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com>

* 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