pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Adrian Klaver <adrian.klaver@aklaver.com>
Cc: Jim Nasby <jim.nasby@gmail.com>
Cc: 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 18:53:20 -0500
Message-ID: <341384.1705017200@sss.pgh.pa.us> (raw)
In-Reply-To: <f4fc9c8d-c8fb-4da2-a0f6-ace98cbc7b40@aklaver.com>
References: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM>
	<cc4d16e8-3263-41e1-9a82-4410c0bdd347@gmail.com>
	<f4fc9c8d-c8fb-4da2-a0f6-ace98cbc7b40@aklaver.com>

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





view thread (21+ messages)  latest in thread

Message-ID: <341384.1705017200@sss.pgh.pa.us>
Permalink:  ../341384.1705017200@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/341384.1705017200@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, adrian.klaver@aklaver.com, jim.nasby@gmail.com, a.hertroijs@nieuwestroom.nl
  Subject: Re: Time zone offset in to_char()
  In-Reply-To: <341384.1705017200@sss.pgh.pa.us>
  References: <DB8P189MB1046C0D82500690791CED07AE2682@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM> <cc4d16e8-3263-41e1-9a82-4410c0bdd347@gmail.com> <f4fc9c8d-c8fb-4da2-a0f6-ace98cbc7b40@aklaver.com> <341384.1705017200@sss.pgh.pa.us>

* 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