Re: JSON for PG 9.2 - Mailing list pgsql-hackers

From Robert Haas
Subject Re: JSON for PG 9.2
Date
Msg-id CA+TgmobE9D=ERO4zfydvh4Fr0W2axzMjw181uGryTLsRGf24vg@mail.gmail.com
Whole thread Raw
In response to Re: JSON for PG 9.2  (Simon Riggs <simon@2ndQuadrant.com>)
Responses Re: JSON for PG 9.2
Re: JSON for PG 9.2
Re: JSON for PG 9.2
List pgsql-hackers
On Mon, Dec 12, 2011 at 3:38 PM, Simon Riggs <simon@2ndquadrant.com> wrote:
> Rather than fuss with specific data formats, why not implement
> something a little more useful?
>
> At present we can have typmods passed as a cstring, so it should be
> possible to add typmods onto the TEXT data type.
>
> e.g. TEXT('JSON'), TEXT('JSONB')
>
> We then invent a new catalog table called pg_text_format which has
> oid PRIMARY KEY
> textformatname UNIQUE
> textformatvalidationproc
> textformatstorageproc
>
> The typmod must reduce to a single integer, so we just store the
> integer. If no typmod, we store 0, so we have a fastpath for normal
> TEXT datatypes.
>
> This would then allow people to have variations of the TEXT type that
> supports conversions, casts, indexing etc without additional fuss and
> without everything else outside the database breaking because it
> doesn't know that datatype name.
>
> We could then support JSON (both kinds), YAML, etc
> as well as providing a way to add validation into the datatype itself.
> We can replace citext with TEXT('CASE_INSENSITIVE')
>
> Think of this as using the object-relational capabilities of Postgres
> to extend the TEXT data type.

Well, it's arguable that text-format JSON and YAML and our existing
XML datatype ought to share some structure with text, but
binary-format JSON is a different animal altogether; you might as well
propose having text('int8').  In any case, I doubt that trying to make
the typmod provide subclassing behavior is going to work out very
well.  There are way too many places that assume that the typmod can
just be discarded.  I don't think that's going to fly, because
=(text,text) probably has different semantics from =(json,json).

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


pgsql-hackers by date:

Previous
From: Marti Raudsepp
Date:
Subject: Re: [PATCH] Caching for stable expressions with constant arguments v3
Next
From: Alvaro Herrera
Date:
Subject: Re: foreign key locks, 2nd attempt