Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nw2pD-00031j-Lu for pgsql-bugs@arkaria.postgresql.org; Tue, 31 May 2022 14:26:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nw2pC-00082x-KA for pgsql-bugs@arkaria.postgresql.org; Tue, 31 May 2022 14:26:22 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nw2pC-00081u-Bb for pgsql-bugs@lists.postgresql.org; Tue, 31 May 2022 14:26:22 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nw2pA-0000r2-8V for pgsql-bugs@lists.postgresql.org; Tue, 31 May 2022 14:26:21 +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 24VEQFsW172787; Tue, 31 May 2022 10:26:15 -0400 From: Tom Lane To: "David G. Johnston" cc: Gregory Jensen , "pgsql-bugs@lists.postgresql.org" Subject: Re: Inconsistent time zone output for JSON at UTC In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Tue, 31 May 2022 05:00:34 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <172785.1654007175.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 31 May 2022 10:26:15 -0400 Message-ID: <172786.1654007175@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > This is the solution. The timezone setting isn't a =E2=80=9Cserver sett= ing=E2=80=9D, it is > a session-local setting with an initial value based upon server > configuration. Change it for the session to UTC if you for some reason > must output +00. > The at time zone operator outputs a timestamp without timezone and that = is > why those variants don=E2=80=99t produce any time zone offset. The use of JSON has nothing whatever to do with this; you're just getting an equivalent of the string representation of the timestamp. It is modified to fit some ISO format spec or other, but it's the same data: regression=3D# show timezone; TimeZone = ------------------ America/New_York (1 row) regression=3D# select now(), to_json(now()); now | to_json = -------------------------------+------------------------------------ 2022-05-31 10:22:00.413512-04 | "2022-05-31T10:22:00.413512-04:00" (1 row) regression=3D# set timezone to 'UTC'; SET regression=3D# select now(), to_json(now()); now | to_json = -------------------------------+------------------------------------ 2022-05-31 14:22:03.559057+00 | "2022-05-31T14:22:03.559057+00:00" (1 row) If you use timestamp-without-time-zone, you get something like regression=3D# select localtimestamp, to_json(localtimestamp); localtimestamp | to_json = ----------------------------+------------------------------ 2022-05-31 14:24:34.927072 | "2022-05-31T14:24:34.927072" (1 row) regards, tom lane