Re: Time zone offset in to_char() - Mailing list pgsql-general

From Tom Lane
Subject Re: Time zone offset in to_char()
Date
Msg-id 341384.1705017200@sss.pgh.pa.us
Whole thread Raw
In response to Re: Time zone offset in to_char()  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses Re: Time zone offset in to_char()
List pgsql-general
Adrian Klaver <adrian.klaver@aklaver.com> writes:
> test=# select to_char(now() AT TIME ZONE 'Europe/Amsterdam', 'YYYY-MM-DD 
> HH24:MI:SS.US0 TZH:TZM') ;
>                to_char
> ------------------------------------
>   2024-01-12 00:44:57.5421420 +00:00
> (1 row)

> You end up with string that does not the correct offset as the AT TIME 
> ZONE outputs a timestamp not timestamptz value.

Yeah.  to_char() does not have any source for the TZ/TZH/TZM fields
other than the prevailing value of the timezone parameter, so you
really have to set that the way you want if you desire to use these
format fields.  As noted upthread, SET LOCAL together with a (dummy)
"SET timezone" clause in the function definition can be used to get
the effect of a function-local setting of the parameter.  I don't
know of another way to achieve that result above the C-code level.

            regards, tom lane



pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Time zone offset in to_char()
Next
From: Jim Nasby
Date:
Subject: Re: Refresh Materialized View Issue