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 1rOLOu-003OX8-Ph for pgsql-general@arkaria.postgresql.org; Fri, 12 Jan 2024 17:33:01 +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 1rOLOt-004BVP-Lf for pgsql-general@arkaria.postgresql.org; Fri, 12 Jan 2024 17:32:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rOLOt-004BVH-BW for pgsql-general@lists.postgresql.org; Fri, 12 Jan 2024 17:32:59 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rOLOq-001EM9-NA for pgsql-general@lists.postgresql.org; Fri, 12 Jan 2024 17:32:58 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailout.nyi.internal (Postfix) with ESMTP id 251065C0096; Fri, 12 Jan 2024 12:32:55 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Fri, 12 Jan 2024 12:32:55 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1705080775; x=1705167175; bh=Nq4UuTJfbKY+9NJid7sQ0UXqSrh/Uclo6IItBOBqJ9k=; b= IPhKxhNkw4muFiUCTbWINgFZorgZJSd0Vw1xN+2JLay6z+hC5zDtD7S4yyRihQ34 kuer5hjmrq20bGVBs8AYKQauDQ6b2EF7BwDEs4+rjge8GviQ3IjqYl4NnqfWq1No qk8mMuYgv/Ll+IC9KvDPYETpJgxf1Q20CLvt6oIikWgzfd5G0IapMngq9Qj3XLtm qnuzr2osh/s3f+L3uuvBwSA3NmS3sa+V86OlrLV6hbS/aslbYzk0v3Ejv1tSSno3 LvQqDKoVAcKvZtC4sQFMuoICgWEV1lLQ2BKtttGwG2p2tX4ukbtDW2z2YuyExwsx FNUcDr4S9mZ6wC8Q011M9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1705080775; x= 1705167175; bh=Nq4UuTJfbKY+9NJid7sQ0UXqSrh/Uclo6IItBOBqJ9k=; b=D dvAITWIuU219Mlz5N3VZL3EOovwpSx2PjHFVcLo07hhAmKfmlvECyZIVHwZDq7t7 ewMvLlwBt+QW3mSl3WlgOoFr9BsHqD0/gzPI87yBqRt9HTMh2vrpHQ2PidHXxomE G1wJVYccYqZY8TrFZO8ux+YZPIxkF6wTUhZFJIcE33nJPIvDCadpsziYUNqD0l3d E6Zv6c7GazIVmJorA9u7q9XlptHi19wP4/QcjY4S8IUF3kUYMxKIXgBIl4u0diiH RJeGleu3nuNEcHBA/0camwWXkuovD92SChmAWksQ9Rm0DRRc46rHVkumFdQG7JaH /JpOD5mJHgWgSL+K9+wEw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrvdeihedguddttdcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomheptegu rhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrd gtohhmqeenucggtffrrghtthgvrhhnpeefgeefieeutdfggfetgefgheekjeehteeileei gfetieekjedvieeviefgheevtdenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmh epmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 12 Jan 2024 12:32:53 -0500 (EST) Message-ID: <9b76331e-0fa9-4ede-99f6-159bd9bf3da3@aklaver.com> Date: Fri, 12 Jan 2024 09:32:53 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Time zone offset in to_char() Content-Language: en-US To: Alban Hertroijs , Alban Hertroys Cc: "pgsql-general@lists.postgresql.org" References: <11b56239-9f18-4b94-aeac-395648a2bfe3@aklaver.com> <752055E6-31DA-404F-AB5E-0BAB83836108@gmail.com> <5bd216b2-4c55-4832-8b9c-bbda9b636bd4@aklaver.com> From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 1/12/24 02:01, Alban Hertroijs wrote: > ciscache=> select ToDatetimeOffset(current_timestamp, > 'Europe/Amsterdam'), to_char(current_timestamp, 'YYYY-MM-DD > HH24:MI:SS.US0 TZH:TZM'); > ERROR:  invalid value for parameter "TimeZone": "tz_" > CONTEXT:  SQL statement "set local timezone to tz_" > PL/pgSQL function todatetimeoffset(timestamp with time zone,text) line 4 > at SQL statement > > But set_config() doesn't have that issue. An example of how to deal with this: CREATE OR REPLACE FUNCTION public.todatetimeoffset(ts_ timestamp with time zone, tz_ text) RETURNS character varying LANGUAGE plpgsql AS $function$ begin --perform set_config('timezone', tz_, true /* local */); EXECUTE 'set local timezone to ' || quote_literal(tz_); return to_char(ts_, 'YYYY-MM-DD HH24:MI:SS.US0 TZH:TZM'); end; $function$ select ToDatetimeOffset(now(), 'Europe/Amsterdam'); todatetimeoffset ------------------------------------ 2024-01-12 18:32:02.5486820 +01:00 -- Adrian Klaver adrian.klaver@aklaver.com