Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO4rX-0016RA-I3 for pgsql-general@arkaria.postgresql.org; Thu, 11 Jan 2024 23:53:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rO4rW-00GD3q-L5 for pgsql-general@arkaria.postgresql.org; Thu, 11 Jan 2024 23:53:26 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO4rW-00GD3h-Aa for pgsql-general@lists.postgresql.org; Thu, 11 Jan 2024 23:53:26 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rO4rT-0015iD-NG for pgsql-general@lists.postgresql.org; Thu, 11 Jan 2024 23:53:25 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 40BNrKUn341385; Thu, 11 Jan 2024 18:53:20 -0500 From: Tom Lane To: Adrian Klaver cc: Jim Nasby , Alban Hertroijs , "pgsql-general@lists.postgresql.org" Subject: Re: Time zone offset in to_char() In-reply-to: References: Comments: In-reply-to Adrian Klaver message dated "Thu, 11 Jan 2024 15:46:56 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <341383.1705017200.1@sss.pgh.pa.us> Date: Thu, 11 Jan 2024 18:53:20 -0500 Message-ID: <341384.1705017200@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver 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