Re: BUG #12578: row_to_json() and to_json() add 'T' in timestamp field.

From: Hor Meng Yoong <yoonghm(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #12578: row_to_json() and to_json() add 'T' in timestamp field.
Date: 2015-01-17 17:27:41
Message-ID: CAEKCi_-sP8W_F5oC0bhNQesy2W0ZO7v6xfuf2LJwxZAWaF1RmQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Thanks for the insights.

I have submitted a documentation comment on PostgreSQL 9.4 document,
Section 9.6, to add in examples on
to_json() and row_to_json() using now() to illustrate ISO 8601. For
examples:

postgres=# select to_json(now());
to_json
------------------------------------
"2015-01-18T01:24:24.488214+08:00"
(1 row)

postgres=# select to_json(now()::TEXT);
to_json
---------------------------------
"2015-01-18 01:24:36.881821+08"
(1 row)

ems=# select row_to_json(row(now()));
row_to_json
-------------------------------------------
{"f1":"2015-01-18T01:26:28.082628+08:00"}
(1 row)

ems=# select row_to_json(row(now()::TEXT));
row_to_json
----------------------------------------
{"f1":"2015-01-18 01:26:40.867813+08"}
(1 row)

On Sat, Jan 17, 2015 at 11:59 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> yoonghm(at)gmail(dot)com writes:
> > row_to_json and to_json replace the space between date and time.
>
> This is not a bug; it's an intentional behavioral change. Per the
> third bullet point in the 9.4 release notes:
>
> * When converting values of type date, timestamp or timestamptz to JSON,
> render the values in a format compliant with ISO 8601 (Andrew Dunstan)
>
> Previously such values were rendered according to the current DateStyle
> setting; but many JSON processors require timestamps to be in ISO 8601
> format. If necessary, the previous behavior can be obtained by
> explicitly casting the datetime value to text before passing it to the
> JSON conversion function.
>
>
> regards, tom lane
>

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message David G Johnston 2015-01-17 19:09:57 Re: BUG #12578: row_to_json() and to_json() add 'T' in timestamp field.
Previous Message Tom Lane 2015-01-17 15:59:17 Re: BUG #12578: row_to_json() and to_json() add 'T' in timestamp field.