Re: Inconsistent time zone output for JSON at UTC

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: Gregory Jensen <GreatDJonfire(at)hotmail(dot)co(dot)uk>, "pgsql-bugs(at)lists(dot)postgresql(dot)org" <pgsql-bugs(at)lists(dot)postgresql(dot)org>
Subject: Re: Inconsistent time zone output for JSON at UTC
Date: 2022-05-31 14:26:15
Message-ID: 172786.1654007175@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> This is the solution. The timezone setting isn't a “server setting”, 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’t 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=# show timezone;
TimeZone
------------------
America/New_York
(1 row)

regression=# 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=# set timezone to 'UTC';
SET
regression=# 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=# 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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2022-05-31 14:43:00 Re: BUG #17485: Records missing from Primary Key index when doing REINDEX INDEX CONCURRENTLY
Previous Message Gregory Jensen 2022-05-31 12:44:08 Re: Inconsistent time zone output for JSON at UTC