Re: Should the JSON datatype be a specialization of text? - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Should the JSON datatype be a specialization of text?
Date
Msg-id 4301.1276788306@sss.pgh.pa.us
Whole thread Raw
In response to Re: Should the JSON datatype be a specialization of text?  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Should the JSON datatype be a specialization of text?  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Thu, Jun 17, 2010 at 2:29 AM, Joseph Adams
> <joeyadams3.14159@gmail.com> wrote:
>> � � � �* No surprises when casting between JSON and TEXT. �If approach B is
>> used, '"string"'::json would be '"string"', but '"string"'::json::text
>> would be 'string'.

> As far as I'm concerned, that's a non-starter.  It should be legal to
> cast text to json, but what it should do is validate that the string
> is already legal JSON, not quote it as a string.

I'm not really convinced about that.  It seems clear to me that there
are two behaviors that we'd like:

1. Take a string that is legal JSON, and make it into a JSON object.

2. Take an arbitrary string (or a number, a bool, etc) and make it a
literal value within a JSON object.

We can make one of these behaviors be invoked by a cast, and the other
by an explicit function call --- the question is which is which.  I'm
inclined to think that associating #2 with casts might be better,
because clearly casting numerics or bools to JSON ought to act like #2.
If we do it as you suggest then casting text to JSON behaves differently
from casting anything else to JSON.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump does not honor namespaces when functions are used in index
Next
From: Greg Stark
Date:
Subject: Re: pg_dump does not honor namespaces when functions are used in index