Re: data to json enhancements

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: data to json enhancements
Date: 2012-09-27 14:09:29
Message-ID: 50645E19.9040108@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 09/27/2012 09:22 AM, Robert Haas wrote:
> On Wed, Sep 26, 2012 at 1:46 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Also, on reflection I'm not sure about commandeering cast-to-json for
>> this --- aren't we really casting to "json member" or something like
>> that? The distinction between a container and its contents seems
>> important here. With a container type as source, it might be important
>> to do something different if we're coercing it to a complete JSON
>> value versus something that will be just one member. I'm handwaving
>> here because I don't feel like going back to re-read the RFC, but
>> it seems like something that should be considered carefully before
>> we lock down an assumption that there can never be a difference.
> I feel like there are two different behaviors that someone might want
> here, and a cast cannot mean both.
[snip]
>
> Maybe I am being too pedantic about this and there is a way to make it
> all work nicely, but it sure feels like using the casting machinery
> here is blending together two different concepts that are only
> sometimes the same.

OK. I think that's a very good point. I guess I was kinda swept away by
this being suggested by a couple of influential people.

[pause for another bout of vigorous self-criticism]

So how about this suggestion: we'll look for a visible function named
"as_json" or some such which has one parameter of the given type and
returns json, and if it's present use it instead of the standard text
representation. As an optimization we'll skip that lookup for builtin
types, since there won't be one. Of course, we'll have one for hstore.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2012-09-27 14:36:47 Re: data to json enhancements
Previous Message Alvaro Herrera 2012-09-27 14:00:44 Re: [v9.3] Extra Daemons (Re: elegant and effective way for running jobs inside a database)