On Tue, 2012-05-01 at 21:22 -0400, David Johnston wrote:
> On May 1, 2012, at 20:41, Hannu Krosing <ha...@2ndquadrant.com> wrote:
> > 
> > Most people don't work in strongly-typed environment, and thus would
> > work around such restriction if they need a simple JSON value at the
> > other end of the interchange.
> > 
> > 
> >> My personal take it is have it fail since any arbitrary decision to cast 
> >> to JSON Text

For arrays and records the json text and jason value are exactly the
same. it is just that json representations of simple types are
officially not JSON texts.

>  is going to make someone unhappy and supposedly they can 
> >> modify their query so that the result generates whatever format they 
> >> desire.
> > 
> > Do you actually have such an experience or is it just a wild guess ?
> > 
> > 
> So even given the semantic differences between an object and a scalar 
> I am better understanding where interpreting JSON as JSON Value makes 
> sense.  However, if I convert a record or array to JSON I expect to get 
> a JSON Text even if the there is only a single column or value in the input.  

Of course you will, and you will get a Json Text even for empty object
or array. 

array[1] and 1 and {'one':1} are all different and will stay such.

> I guess my take is that record -> JSON text while anything else is JSON 
> value.  Whether it is worth maiming the special case for record is 
> worthwhile I really do not know but the semantic difference does exist; 
> and record output is a significant aspect of PostgreSQL output.

I have never suggested that we special-case an 1-element record or list
and start returning only the contained value for these.

> I get the ease-of-use aspect but also recognize that sometimes being slightly 
> harder to use is worthwhile if you eliminate ambiguities or limit the 
> possibility to make mistakes.

There are no ambiguities in what is returnded for record or array.

But not being able to return JSON values via cast to json for some types
or not using such casts will make extending the json support for types
by user much much harder. And nonstandard. 

Using simple cast to json is very PostgreSQL-ish way to give support of
json to any type

Hannu Krosing
PostgreSQL Unlimited Scalability and Performance Consultant
2ndQuadrant Nordic
PG Admin Book: http://www.2ndQuadrant.com/books/

Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:

Reply via email to