Re: Initial Review: JSON contrib modul was: Re: Another swing at JSON

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Joey Adams <joeyadams3(dot)14159(at)gmail(dot)com>
Cc: Florian Pflug <fgp(at)phlo(dot)org>, pgsql-hackers(at)postgresql(dot)org, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Bernd Helmle <mailings(at)oopsware(dot)de>, Dimitri Fontaine <dimitri(at)2ndquadrant(dot)fr>, David Fetter <david(at)fetter(dot)org>, Josh Berkus <josh(at)agliodbs(dot)com>
Subject: Re: Initial Review: JSON contrib modul was: Re: Another swing at JSON
Date: 2011-07-24 03:14:50
Message-ID: CA+TgmoYxnRg5etC6CuPf7X_Sw6pSFeJVMjUEhSm0=4fFAvxc9A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Jul 22, 2011 at 10:36 PM, Joey Adams <joeyadams3(dot)14159(at)gmail(dot)com> wrote:
> Interesting.  This leads to a couple more questions:
>
>  * Should the JSON data type (eventually) have an equality operator?

+1.

>  * Should the JSON input function alphabetize object members by key?

I think it would probably be better if it didn't. I'm wary of
overcanonicalization. It can be useful to have things come back out
in more or less the format you put them in.

> If we canonicalize strings and numbers and alphabetize object members,
> then our equality function is just texteq.  The only stumbling block
> is canonicalizing numbers.  Fortunately, JSON's definition of a
> "number" is its decimal syntax, so the algorithm is child's play:
>
>  * Figure out the digits and exponent.
>  * If the exponent is greater than 20 or less than 6 (arbitrary), use
> exponential notation.
>
> The problem is: 2.718282e-1000 won't equal 0 as may be expected.  I
> doubt this matters much.

I don't think that 2.718282e-100 SHOULD equal 0.

> If, in the future, we add the ability to manipulate large JSON trees
> efficiently (e.g. by using an auxiliary table like TOAST does), we'll
> probably want unique members, so enforcing them now may be prudent.

I doubt you're going to want to reinvent TOAST, but I do think there
are many advantages to forbidding duplicate keys. ISTM the question
is whether to throw an error or just silently discard one of the k/v
pairs. Keeping both should not be on the table, IMHO.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 2011-07-24 05:46:08 Re: Problem with pg_upgrade's directory write check on Windows
Previous Message Joey Adams 2011-07-24 03:09:45 Re: Initial Review: JSON contrib modul was: Re: Another swing at JSON