pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Relaxing NaN/Infinity restriction in JSON fields
5+ messages / 3 participants
[nested] [flat]

* Relaxing NaN/Infinity restriction in JSON fields
@ 2019-05-06 19:55 Mitar <mmitar@gmail.com>
  2019-05-06 20:21 ` Re: Relaxing NaN/Infinity restriction in JSON fields Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 5+ messages in thread

From: Mitar @ 2019-05-06 19:55 UTC (permalink / raw)
  To: pgsql-general

Hi!

When migrating from MongoDB to PostgreSQL one thing which just
surprised me now is that I cannot store NaN/Infinity in JSON fields. I
know that standard JSON restricts those values, but they are a very
common (and welcome) relaxation. What are prospects of this
restriction being lifted? It is really sad that one cannot stores
directly all IEEE 754 double precision floating point values.


Mitar

-- 
http://mitar.tnode.com/
https://twitter.com/mitar_m





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Relaxing NaN/Infinity restriction in JSON fields
  2019-05-06 19:55 Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
@ 2019-05-06 20:21 ` Tom Lane <tgl@sss.pgh.pa.us>
  2019-05-08 06:09   ` Re: Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2019-05-06 20:21 UTC (permalink / raw)
  To: Mitar <mmitar@gmail.com>; +Cc: pgsql-general

Mitar <mmitar@gmail.com> writes:
> When migrating from MongoDB to PostgreSQL one thing which just
> surprised me now is that I cannot store NaN/Infinity in JSON fields. I
> know that standard JSON restricts those values, but they are a very
> common (and welcome) relaxation. What are prospects of this
> restriction being lifted?

The JSON RFC is pretty clear on this matter [1]:

   Numeric values that cannot be represented in the grammar below (such
   as Infinity and NaN) are not permitted.

Getting us to deviate from the RFC so blatantly would be a very hard sell.
A large part of the point of the JSON datatype is to be interoperable;
once you give that up you may as well use some not-standard-at-all
representation.

> It is really sad that one cannot stores
> directly all IEEE 754 double precision floating point values.

There is not, and never has been, any claim that JSON numbers correspond
to the IEEE spec.

			regards, tom lane

[1] https://tools.ietf.org/html/rfc7159#page-6





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Relaxing NaN/Infinity restriction in JSON fields
  2019-05-06 19:55 Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  2019-05-06 20:21 ` Re: Relaxing NaN/Infinity restriction in JSON fields Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-05-08 06:09   ` Mitar <mmitar@gmail.com>
  2019-05-08 13:09     ` Re: Relaxing NaN/Infinity restriction in JSON fields Alvaro Herrera <alvherre@2ndquadrant.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Mitar @ 2019-05-08 06:09 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-general

Hi!

On Mon, May 6, 2019 at 1:21 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Getting us to deviate from the RFC so blatantly would be a very hard sell.
> A large part of the point of the JSON datatype is to be interoperable;
> once you give that up you may as well use some not-standard-at-all
> representation.

Python supports that, enabled by default:

https://docs.python.org/3/library/json.html#infinite-and-nan-number-values

> There is not, and never has been, any claim that JSON numbers correspond
> to the IEEE spec.

There is note [1], but yes, it does not claim that nor I claimed that.
I am just saying that the reality is that most people these days use
IEEE spec floating numbers so it is sad that those cannot be easily
stored in JSON, or a database.


Mitar

[1] https://tools.ietf.org/html/rfc7159#page-7

-- 
http://mitar.tnode.com/
https://twitter.com/mitar_m





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Relaxing NaN/Infinity restriction in JSON fields
  2019-05-06 19:55 Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  2019-05-06 20:21 ` Re: Relaxing NaN/Infinity restriction in JSON fields Tom Lane <tgl@sss.pgh.pa.us>
  2019-05-08 06:09   ` Re: Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
@ 2019-05-08 13:09     ` Alvaro Herrera <alvherre@2ndquadrant.com>
  2019-05-08 17:11       ` Re: Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Alvaro Herrera @ 2019-05-08 13:09 UTC (permalink / raw)
  To: Mitar <mmitar@gmail.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

On 2019-May-07, Mitar wrote:

> On Mon, May 6, 2019 at 1:21 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> > There is not, and never has been, any claim that JSON numbers correspond
> > to the IEEE spec.
> 
> There is note [1], but yes, it does not claim that nor I claimed that.
> I am just saying that the reality is that most people these days use
> IEEE spec floating numbers so it is sad that those cannot be easily
> stored in JSON, or a database.

If you want to complain about JSON, it's IETF that you need to talk
about, not us -- we're just implementing their spec.  As for storing the
numbers in a database, you can already do that, just not on the JSON
datatype.

There is a lot of talk in the json mailing list about subnormals and why
they don't want them valid in JSON because of interoperability, and that
discussion led to the wording present in RFC7159; strangely, the wording
there about Inf/NaN predates that discussion (it's already there in
RFC4627) and I couldn't find the rationale for they being disallowed.

-- 
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Relaxing NaN/Infinity restriction in JSON fields
  2019-05-06 19:55 Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  2019-05-06 20:21 ` Re: Relaxing NaN/Infinity restriction in JSON fields Tom Lane <tgl@sss.pgh.pa.us>
  2019-05-08 06:09   ` Re: Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
  2019-05-08 13:09     ` Re: Relaxing NaN/Infinity restriction in JSON fields Alvaro Herrera <alvherre@2ndquadrant.com>
@ 2019-05-08 17:11       ` Mitar <mmitar@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Mitar @ 2019-05-08 17:11 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@2ndquadrant.com>; +Cc: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-general

Hi!

On Wed, May 8, 2019 at 6:09 AM Alvaro Herrera <alvherre@2ndquadrant.com> wrote:
> If you want to complain about JSON, it's IETF that you need to talk
> about, not us -- we're just implementing their spec.  As for storing the
> numbers in a database, you can already do that, just not on the JSON
> datatype.

Yes, I see why then so many implement variations on JSON, like BSON
and stuff. So that they can have mostly compatible structure, but with
all floats and datetime structure.

What are thoughts of adding something like that? PgJSON variant. :-)


Mitar

-- 
http://mitar.tnode.com/
https://twitter.com/mitar_m





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-05-08 17:11 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 19:55 Relaxing NaN/Infinity restriction in JSON fields Mitar <mmitar@gmail.com>
2019-05-06 20:21 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-05-08 06:09   ` Mitar <mmitar@gmail.com>
2019-05-08 13:09     ` Alvaro Herrera <alvherre@2ndquadrant.com>
2019-05-08 17:11       ` Mitar <mmitar@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox