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 1rBJtP-00AOEA-2y for pgsql-docs@arkaria.postgresql.org; Thu, 07 Dec 2023 19:18:39 +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 1rBJtN-001yOF-Nq for pgsql-docs@arkaria.postgresql.org; Thu, 07 Dec 2023 19:18:37 +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 1rBJtN-001yO7-Ai for pgsql-docs@lists.postgresql.org; Thu, 07 Dec 2023 19:18:37 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBJtK-00Ablr-EF for pgsql-docs@postgresql.org; Thu, 07 Dec 2023 19:18:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=momjian.us; s=2023062407; h=In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description; bh=vwwReBxr63Y9KTEoEKyiHhO6PXbS+aXYkS57N8gx53o=; b=0Tg0S lTviZvDF76Swy6jVe0xDgocBKThrigAxQ4K/uvMYPpcgQZvJegXVelRt4oVsKlUSRe9z4nQd83SJe tbSp2f8VfD7q+I8qHFE3DOTa727l3aIu32SbmcTIia+ifFrk06/mRwgFZR7KlLfWUK4WWQoiZDy5E afhUQ+VjHAtSh8UvSwLkbK17HoKBo3tuWx16ySXkUfhwgzEaU/+FVMIKqn2wZ3EOE4jFUUP+GNBUT 9TLvLzjlUIsj+kroR2xc8Tvsu+7vvSBBY56hehPyxxodULUWlweDK0N79uYu9TzgTpOYHr/n6qACW OlhJ6K5x+tWP1/5GzFVfC2peH3WZw==; Received: from bruce by momjian.us with local (Exim 4.96) (envelope-from ) id 1rBJtE-00ATmt-1h; Thu, 07 Dec 2023 14:18:28 -0500 Date: Thu, 7 Dec 2023 14:18:28 -0500 From: Bruce Momjian To: Erik Wienhold Cc: Alvaro Herrera , Laurenz Albe , juha.mustonen@iki.fi, pgsql-docs@postgresql.org Subject: Re: [DOCS] Add example about date ISO format Message-ID: References: <202311271422.j6abzoo2x44p@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="phvOWs4fWz15ap9d" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --phvOWs4fWz15ap9d Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Mon, Nov 27, 2023 at 04:52:20PM +0100, Erik Wienhold wrote: > On 2023-11-27 15:22 +0100, Alvaro Herrera wrote: > > On 2023-Nov-27, Erik Wienhold wrote: > > > > > Two issues that I fixed in the attached patch: > > > > > > * it's called "extended format" not "T format" (the "T" is mandatory > > > anyway) > > > > +1 > > > > > * the time zone was missing from the result output > > > > This is wrong. Actually, there's no timezone in value, because the use > > of the AT TIME ZONE operator makes the type be TIMESTAMP WITHOUT TIME > > ZONE. You would notice this if you were to change the incorrect literal > > Z in your format string with "TZ" (which expands to empty), with "OF" > > (which expands to "+00"), or with "TZH:TZM" (which expands to the full > > timezone shift): > > Thanks for the explanation. Bruce used literal Z in the format string. > I just corrected the sample output to match the format. > > Or we just use current_timestamp along with pattern TZH:TZM which also > adds less to the width of the displayed table in case Bruce is concerned > about that ;) Yes, there were a few problems with my initial patch. First, I should have used "Z" instead of a Z which could be interpreted as a format specification; I had already done that for "T" in the example. Second, I was missing the trailing "Z" in the output --- not sure how that happened. Erik and Alvaro made a great point --- we are using a literal "Z" as the time zone output specification, but as Alvaro pointed out, there is no way to get the time zone _name_ or even the offset from the AT TIME ZONE value, so we must just pass the literal "Z" from the input to the output. This proves Alvaro's point on this issue: SELECT pg_typeof(current_timestamp AT TIME ZONE 'America/Santiago'); pg_typeof ----------------------------- timestamp without time zone Updated patch attached. Thank you for the feedback. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Only you can decide what is important to you. --phvOWs4fWz15ap9d Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="iso.diff" diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 20da3ed033..cec21e42c0 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -8748,6 +8748,12 @@ SELECT regexp_match('abc01234xyz', '(?:(.*?)(\d+)(.*)){1,1}'); to_char(current_timestamp, 'FMDay, FMDD  HH12:MI:SS') 'Tuesday, 6  05:39:18' + + to_char(current_timestamp AT TIME ZONE + 'UTC', 'YYYY-MM-DD"T"HH24:MI:SS"Z"') + '2022-12-06T05:39:18Z', + ISO 8601 extended format + to_char(-0.1, '99.99') '  -.10' --phvOWs4fWz15ap9d--