Thread: Feature Request: JSON input for hstore

Feature Request: JSON input for hstore

From
Josh Berkus
Date:
Hackers,

I've just had a feature request from a client that we come up with a way
to enable JSON input into hstore.  This would make hstore much more
useful for software developers.

First question: would this go in the language driver, libpq, or the
backend?  Thoughts?

-- 
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


Re: Feature Request: JSON input for hstore

From
David Fetter
Date:
On Mon, Sep 14, 2009 at 03:14:57PM -0700, Josh Berkus wrote:
> Hackers,
> 
> I've just had a feature request from a client that we come up with a
> way to enable JSON input into hstore.  This would make hstore much
> more useful for software developers.
> 
> First question: would this go in the language driver, libpq, or the
> backend?  Thoughts?

The backend, ideally in some pluggable way.  XML, under proper
circumstances, should work, as should YAML, etc.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


Re: Feature Request: JSON input for hstore

From
Andrew Dunstan
Date:

David Fetter wrote:
> On Mon, Sep 14, 2009 at 03:14:57PM -0700, Josh Berkus wrote:
>   
>> Hackers,
>>
>> I've just had a feature request from a client that we come up with a
>> way to enable JSON input into hstore.  This would make hstore much
>> more useful for software developers.
>>
>> First question: would this go in the language driver, libpq, or the
>> backend?  Thoughts?
>>     
>
> The backend, ideally in some pluggable way.  XML, under proper
> circumstances, should work, as should YAML, etc.
>
>
>   

The way the standard specifies SQL/XML requires grammar support. That 
means it can't really be pluggable. We've been over this before.

chjeers

andrew


Re: Feature Request: JSON input for hstore

From
Tom Lane
Date:
David Fetter <david@fetter.org> writes:
> On Mon, Sep 14, 2009 at 03:14:57PM -0700, Josh Berkus wrote:
>> I've just had a feature request from a client that we come up with a
>> way to enable JSON input into hstore.  This would make hstore much
>> more useful for software developers.
>> 
>> First question: would this go in the language driver, libpq, or the
>> backend?  Thoughts?

> The backend, ideally in some pluggable way.  XML, under proper
> circumstances, should work, as should YAML, etc.

Uh, hstore is a contrib module.  Why aren't we talking about just some
more code in the contrib module?  Adding anything to support a contrib
module in, say, libpq seems right out.
        regards, tom lane


Re: Feature Request: JSON input for hstore

From
Jeff Davis
Date:
On Mon, 2009-09-14 at 15:14 -0700, Josh Berkus wrote:
> Hackers,
> 
> I've just had a feature request from a client that we come up with a way
> to enable JSON input into hstore.  This would make hstore much more
> useful for software developers.
> 
> First question: would this go in the language driver, libpq, or the
> backend?  Thoughts?

What's wrong with just using a variant of the type input function? With
a parameterized insert, it doesn't seem like it's really placing much of
a burden on the application.

Or am I missing the use case?

Regards,Jeff Davis



Re: Feature Request: JSON input for hstore

From
David Fetter
Date:
On Mon, Sep 14, 2009 at 06:55:52PM -0400, Andrew Dunstan wrote:
> David Fetter wrote:
>> On Mon, Sep 14, 2009 at 03:14:57PM -0700, Josh Berkus wrote:
>>> Hackers,
>>>
>>> I've just had a feature request from a client that we come up with
>>> a way to enable JSON input into hstore.  This would make hstore
>>> much more useful for software developers.
>>>
>>> First question: would this go in the language driver, libpq, or
>>> the backend?  Thoughts?
>>
>> The backend, ideally in some pluggable way.  XML, under proper
>> circumstances, should work, as should YAML, etc.
>
> The way the standard specifies SQL/XML requires grammar support.
> That  means it can't really be pluggable. We've been over this
> before.

I haven't found anything about hstore in the standard, so I'm not sure
how this applies.

Cheers,
David.
-- 
David Fetter <david@fetter.org> http://fetter.org/
Phone: +1 415 235 3778  AIM: dfetter666  Yahoo!: dfetter
Skype: davidfetter      XMPP: david.fetter@gmail.com

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate


Re: Feature Request: JSON input for hstore

From
Robert Haas
Date:
On Sep 14, 2009, at 7:05 PM, Jeff Davis <pgsql@j-davis.com> wrote:

> On Mon, 2009-09-14 at 15:14 -0700, Josh Berkus wrote:
>> Hackers,
>>
>> I've just had a feature request from a client that we come up with  
>> a way
>> to enable JSON input into hstore.  This would make hstore much more
>> useful for software developers.
>>
>> First question: would this go in the language driver, libpq, or the
>> backend?  Thoughts?
>
> What's wrong with just using a variant of the type input function?  
> With
> a parameterized insert, it doesn't seem like it's really placing  
> much of
> a burden on the application.

Agreed, I was thinking the same thing.

...Roberta


Re: Feature Request: JSON input for hstore

From
"David E. Wheeler"
Date:
On Sep 14, 2009, at 4:32 PM, Robert Haas wrote:

>> What's wrong with just using a variant of the type input function?  
>> With
>> a parameterized insert, it doesn't seem like it's really placing  
>> much of
>> a burden on the application.
>
> Agreed, I was thinking the same thing.

And the type output function, too. Not sure how you'd configure that,  
though.

David


Re: Feature Request: JSON input for hstore

From
Robert Haas
Date:
On Mon, Sep 14, 2009 at 7:42 PM, David E. Wheeler <david@kineticode.com> wrote:
> On Sep 14, 2009, at 4:32 PM, Robert Haas wrote:
>
>>> What's wrong with just using a variant of the type input function? With
>>> a parameterized insert, it doesn't seem like it's really placing much of
>>> a burden on the application.
>>
>> Agreed, I was thinking the same thing.
>
> And the type output function, too. Not sure how you'd configure that,
> though.

Well I don't think you really need any them to BE the type
input/output functions.  You just need

hstore_to_json(hstore) returns text
json_to_hstore(text) returns json

Insert into your query where appropriate.

...Robert


Re: Feature Request: JSON input for hstore

From
Andrew Dunstan
Date:

David Fetter wrote:
> On Mon, Sep 14, 2009 at 06:55:52PM -0400, Andrew Dunstan wrote:
>   
>> David Fetter wrote:
>>     
>>> On Mon, Sep 14, 2009 at 03:14:57PM -0700, Josh Berkus wrote:
>>>       
>>>> Hackers,
>>>>
>>>> I've just had a feature request from a client that we come up with
>>>> a way to enable JSON input into hstore.  This would make hstore
>>>> much more useful for software developers.
>>>>
>>>> First question: would this go in the language driver, libpq, or
>>>> the backend?  Thoughts?
>>>>         
>>> The backend, ideally in some pluggable way.  XML, under proper
>>> circumstances, should work, as should YAML, etc.
>>>       
>> The way the standard specifies SQL/XML requires grammar support.
>> That  means it can't really be pluggable. We've been over this
>> before.
>>     
>
> I haven't found anything about hstore in the standard, so I'm not sure
> how this applies.
>
>
>   

You're the one that mentioned the backend being pluggable w.r.t. XML 
among other things.

In any case, this is academic. It has become clear in off-list 
discussion that support for JSON input isn't really what the requestor 
needs. What he needs is a way to translate a Perl hashref to an hstore 
literal and vice versa, and Andrew Gierth has written some nice routines 
in Perl to do just that.

cheers

andrew