| From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
|---|---|
| To: | Alban Hertroys <haramrae(at)gmail(dot)com> |
| Cc: | Alban Hertroys <a(dot)hertroijs(at)nieuwestroom(dot)nl>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Time zone offset in to_char() |
| Date: | 2024-01-11 21:09:00 |
| Message-ID: | 5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
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(dot)klaver(at)aklaver(dot)com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Adrian Klaver | 2024-01-11 21:15:44 | Re: Time zone offset in to_char() |
| Previous Message | Jeremiah Bauer | 2024-01-11 20:50:13 | Re: Refresh Materialized View Issue |