Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-04 Thread Hitoshi Harada
2010/1/4 David E. Wheeler da...@kineticode.com: On Jan 3, 2010, at 4:18 PM, Hitoshi Harada wrote: That sounds good and seems possible, as far as operator returns JSON always. Perhaps every JSON fetching returns JSON even if the result would be a number. You can cast it.   % SELECT

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-04 Thread Robert Haas
On Sun, Jan 3, 2010 at 1:51 PM, David E. Wheeler da...@kineticode.com wrote: On Jan 3, 2010, at 8:00 AM, Andrew Dunstan wrote: I think the minimal functionality I'd want is:   convert record to JSON   convert JSON to record With caveats as to dealing with nested structures (can a record be

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-04 Thread David E. Wheeler
On Jan 4, 2010, at 8:18 PM, Robert Haas wrote: Is this something you are planning to work on for the 2010-01-15 CommitFest? If not, I think we should go ahead and mark the patch which was the original subject of this thread Returned with Feedback, as it does not seem to make sense to add it

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread Andrew Dunstan
Hitoshi Harada wrote: 2010/1/3 Andrew Dunstan and...@dunslane.net: Hitoshi Harada wrote: A question: Isn't there no possibility that we have our own implementation to handle JSON (i.e. no use of external libraries)? Why should we reinvent a wheel someone else has already

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread David E. Wheeler
On Jan 3, 2010, at 8:00 AM, Andrew Dunstan wrote: I think the minimal functionality I'd want is: convert record to JSON convert JSON to record With caveats as to dealing with nested structures (can a record be an attribute of a record?). extract a value, or set of values, from JSON

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread Andrew Dunstan
David E. Wheeler wrote: On Jan 3, 2010, at 8:00 AM, Andrew Dunstan wrote: I think the minimal functionality I'd want is: convert record to JSON convert JSON to record With caveats as to dealing with nested structures (can a record be an attribute of a record?). We allow

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread David E. Wheeler
On Jan 3, 2010, at 11:40 AM, Andrew Dunstan wrote: We allow composites as fields. The biggest mismatch in the type model is probably w.r.t arrays. JSON arrays can be heterogenous and non-rectangular, AIUI. Cool, that sounds right. OK, but hstores are flat, unlike JSON. We need some way to

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread Hitoshi Harada
2010/1/4 David E. Wheeler da...@kineticode.com: On Jan 3, 2010, at 11:40 AM, Andrew Dunstan wrote: We allow composites as fields. The biggest mismatch in the type model is probably w.r.t arrays. JSON arrays can be heterogenous and non-rectangular, AIUI. Cool, that sounds right. Does it

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread Andrew Dunstan
Hitoshi Harada wrote: 2010/1/4 David E. Wheeler da...@kineticode.com: On Jan 3, 2010, at 11:40 AM, Andrew Dunstan wrote: We allow composites as fields. The biggest mismatch in the type model is probably w.r.t arrays. JSON arrays can be heterogenous and non-rectangular, AIUI.

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread David E. Wheeler
On Jan 3, 2010, at 4:18 PM, Hitoshi Harada wrote: That sounds good and seems possible, as far as operator returns JSON always. Perhaps every JSON fetching returns JSON even if the result would be a number. You can cast it. % SELECT ('{foo:{bar:[a,b,c]}}' - '[foo][1]')::text; 1

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-03 Thread Robert Haas
On Sun, Jan 3, 2010 at 11:00 AM, Andrew Dunstan and...@dunslane.net wrote: Hitoshi Harada wrote: 2010/1/3 Andrew Dunstan and...@dunslane.net: Hitoshi Harada wrote: A question: Isn't there no possibility that we have our own implementation to handle JSON (i.e. no use of external libraries)?

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-02 Thread Peter Eisentraut
On fre, 2010-01-01 at 17:19 -0500, Andrew Dunstan wrote: Mine for one :-). Quite apart from any other reason I would expect it to make indexing parts of the JSON more tractable. Say we use it to store a web session object, which is a natural enough use. I might well want to find or modify

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-02 Thread Hitoshi Harada
2010/1/3 Peter Eisentraut pete...@gmx.net: On fre, 2010-01-01 at 17:19 -0500, Andrew Dunstan wrote: Mine for one :-). Quite apart from any other reason I would expect it to make indexing parts of the JSON more tractable. Say we use it to store a web session object, which is a natural enough

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-02 Thread Andrew Dunstan
Hitoshi Harada wrote: A question: Isn't there no possibility that we have our own implementation to handle JSON (i.e. no use of external libraries)? Why should we reinvent a wheel someone else has already invented? This is what shared libraries are all about. cheers andrew -- Sent

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-02 Thread Hitoshi Harada
2010/1/3 Andrew Dunstan and...@dunslane.net: Hitoshi Harada wrote: A question: Isn't there no possibility that we have our own implementation to handle JSON (i.e. no use of external libraries)? Why should we reinvent a wheel someone else has already invented? This is what shared

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-01 Thread Dimitri Fontaine
Andrew Dunstan and...@dunslane.net writes: Does anyone have any real-world experience with any of the JSON C libraries? I do not, but I see that YAJL http://lloyd.github.com/yajl/ is now in Fedora, and has a BSDish license It's there in debian too, unstable and testing, and should be there on

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-01 Thread Peter Eisentraut
On tor, 2009-12-31 at 11:12 -0500, Andrew Dunstan wrote: David E. Wheeler wrote: On Dec 31, 2009, at 1:04 AM, Peter Eisentraut wrote: I think the primary use will be to load a JSON value into Perl or Python and process it there. So a json type that doesn't have any interesting

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-01 Thread Andrew Dunstan
Peter Eisentraut wrote: IMNSHO it's essential. I think Peter's approach of ignoring this requirement is extremely shortsighted. Whose requirement is it? I'm not ignoring it, but so far no one has actually said that it is a requirement and why. Mine for one :-). Quite apart from

Re: [HACKERS] PATCH: Add hstore_to_json()

2010-01-01 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: Peter Eisentraut wrote: Whose requirement is it? I'm not ignoring it, but so far no one has actually said that it is a requirement and why. Mine for one :-). I think there are a couple of interacting factors here. We are not likely to want to go

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Peter Eisentraut
On ons, 2009-12-30 at 12:53 -0500, Robert Haas wrote: It looks like they are all very permissive, though I wonder what the legal effect of a license clause that the software be used for Good and not Evil might be. It's not without issues, apparently:

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Peter Eisentraut
On ons, 2009-12-30 at 13:23 -0500, Andrew Dunstan wrote: I'd like to see at least the outline of an API before we go any further. JSON is, shall we say, lightly specified, and doesn't appear to have any equivalent to XPath and friends, for example. How will we extract values from a JSON

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: RIPEMD160 Doesn't seem insurmountable, though, just one more thing to think about as we're having this conversation. Someone else will need to weigh in on this point though, as I don't use JSON in a way that would make anything beyond validation

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread David E. Wheeler
On Dec 31, 2009, at 1:04 AM, Peter Eisentraut wrote: I think the primary use will be to load a JSON value into Perl or Python and process it there. So a json type that doesn't have any interesting operators doesn't sound useless to me. The features I would like to get out of it are input

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Andrew Dunstan
David E. Wheeler wrote: On Dec 31, 2009, at 1:04 AM, Peter Eisentraut wrote: I think the primary use will be to load a JSON value into Perl or Python and process it there. So a json type that doesn't have any interesting operators doesn't sound useless to me. The features I would like

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Robert Haas
On Thu, Dec 31, 2009 at 11:12 AM, Andrew Dunstan and...@dunslane.net wrote: David E. Wheeler wrote: On Dec 31, 2009, at 1:04 AM, Peter Eisentraut wrote: I think the primary use will be to load a JSON value into Perl or Python and process it there.  So a json type that doesn't have any

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Andrew Dunstan
Robert Haas wrote: Anyhow, that brings me back to the question I asked upthread, which is Can/should we suck one of these libraries into our code base (and if so, which?) or do we need to add an analogue of --with-libxml so that we can link against an external library if present and omit the

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Tom Lane
Robert Haas robertmh...@gmail.com writes: Anyhow, that brings me back to the question I asked upthread, which is Can/should we suck one of these libraries into our code base (and if so, which?) or do we need to add an analogue of --with-libxml so that we can link against an external library if

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-31 Thread Robert Haas
On Thu, Dec 31, 2009 at 5:37 PM, Tom Lane t...@sss.pgh.pa.us wrote: Robert Haas robertmh...@gmail.com writes: Anyhow, that brings me back to the question I asked upthread, which is Can/should we suck one of these libraries into our code base (and if so, which?) or do we need to add an analogue

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread David E. Wheeler
On Dec 29, 2009, at 6:14 PM, Robert Haas wrote: I've been mulling this over and I think this is a pretty good idea. If we could get it done in time for 8.5, we could actually change the output type of EXPLAIN (FORMAT JSON) to the new type. If not, I'm inclined to say that we should postpone

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread Robert Haas
On Wed, Dec 30, 2009 at 12:38 PM, David E. Wheeler da...@kineticode.com wrote: On Dec 29, 2009, at 6:14 PM, Robert Haas wrote: I've been mulling this over and I think this is a pretty good idea. If we could get it done in time for 8.5, we could actually change the output type of EXPLAIN

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread David E. Wheeler
On Dec 30, 2009, at 9:53 AM, Robert Haas wrote: It looks like they are all very permissive, though I wonder what the legal effect of a license clause that the software be used for Good and not Evil might be. Yeah, that might be too restrictive, given that PostgreSQL is used by government

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread Andrew Dunstan
David E. Wheeler wrote: I guess the question is whether we would slurp one of these into our code base, or whether we would add an analog of --with-libxml and provide only a stub implementation when the library is not present. Any opinions? Does anyone know whether any of these

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread Robert Haas
On Wed, Dec 30, 2009 at 1:23 PM, Andrew Dunstan and...@dunslane.net wrote: I think we are getting the cart way before the horse. I'd like to see at least the outline of an API before we go any further. JSON is, shall we say, lightly specified, and doesn't appear to have any equivalent to XPath

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread Andrew Dunstan
Robert Haas wrote: On Wed, Dec 30, 2009 at 1:23 PM, Andrew Dunstan and...@dunslane.net wrote: I think we are getting the cart way before the horse. I'd like to see at least the outline of an API before we go any further. JSON is, shall we say, lightly specified, and doesn't appear to have

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-30 Thread Robert Haas
On Wed, Dec 30, 2009 at 2:26 PM, Andrew Dunstan and...@dunslane.net wrote: Robert Haas wrote: On Wed, Dec 30, 2009 at 1:23 PM, Andrew Dunstan and...@dunslane.net wrote: I think we are getting the cart way before the horse. I'd like to see at least the outline of an API before we go any

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-29 Thread Robert Haas
On Fri, Dec 18, 2009 at 4:39 PM, Peter Eisentraut pete...@gmx.net wrote: On fre, 2009-12-18 at 11:51 -0500, Robert Haas wrote: On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler da...@kineticode.com wrote: On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Peter Eisentraut
On ons, 2009-12-16 at 11:28 -0800, David E. Wheeler wrote: I just realized that this was easy to do, and despite my complete lack of C skillz was able to throw this together in a couple of hours. It might be handy to some, though the possible downsides are: * No json_to_hstore(). * Leads

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread David E. Wheeler
On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type before adding all kinds of json formatted data? Or are we content with json as text? json_data_type++ D -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Robert Haas
On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler da...@kineticode.com wrote: On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type before adding all kinds of json formatted data?  Or are we content with json as text? json_data_type++ What would that do for us?

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread David E. Wheeler
On Dec 18, 2009, at 8:51 AM, Robert Haas wrote: What would that do for us? I'm not opposed to it, but it seems like the more important thing would be to provide functions or operators that can do things like extract an array, extract a hash key, identify whether something is a hash, list,

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Andrew Dunstan
Robert Haas wrote: On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler da...@kineticode.com wrote: On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type before adding all kinds of json formatted data? Or are we content with json as text?

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: You're correct that we don't necessarily need a new type, we could just make it text and have a bunch of operations, but that seems to violate the principle of data type abstraction a bit. I think the relevant precedent is that we have an xml type.

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Andrew Dunstan
Tom Lane wrote: Andrew Dunstan and...@dunslane.net writes: You're correct that we don't necessarily need a new type, we could just make it text and have a bunch of operations, but that seems to violate the principle of data type abstraction a bit. I think the relevant precedent is

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Bruce Momjian
Andrew Dunstan wrote: Tom Lane wrote: Andrew Dunstan and...@dunslane.net writes: You're correct that we don't necessarily need a new type, we could just make it text and have a bunch of operations, but that seems to violate the principle of data type abstraction a bit.

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Tom Lane
Andrew Dunstan and...@dunslane.net writes: Tom Lane wrote: [ I can already hear somebody insisting on a yaml type :-( ] Now that's a case where I think a couple of converter functions at most should meet the need. Well, actually, now that you mention it: how much of a json type would be

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Alvaro Herrera
Tom Lane escribió: Andrew Dunstan and...@dunslane.net writes: Tom Lane wrote: [ I can already hear somebody insisting on a yaml type :-( ] Now that's a case where I think a couple of converter functions at most should meet the need. Well, actually, now that you mention it: how much

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Tom Lane
Alvaro Herrera alvhe...@commandprompt.com writes: Tom Lane escribió: Well, actually, now that you mention it: how much of a json type would be duplicative of the xml stuff? Would it be sufficient to provide json - xml converters and let the latter type do all the heavy lifting? (If so, this

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Robert Haas
On Fri, Dec 18, 2009 at 3:00 PM, Tom Lane t...@sss.pgh.pa.us wrote: Alvaro Herrera alvhe...@commandprompt.com writes: Tom Lane escribió: Well, actually, now that you mention it: how much of a json type would be duplicative of the xml stuff?  Would it be sufficient to provide json - xml

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Ron Mayer
+1 for such a feature, simply to avoid the need of writing a hstore-parser (which wasn't too bad to write, but it felt unnecessary). Doesn't matter to me if it's hstore-to-json or hstore-to-xml or hstore-to-yaml. Just something that parsers are readily available for. Heck, I wouldn't mind if

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Peter Eisentraut
On fre, 2009-12-18 at 11:51 -0500, Robert Haas wrote: On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler da...@kineticode.com wrote: On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type before adding all kinds of json formatted data? Or are we content with

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Robert Haas
On Fri, Dec 18, 2009 at 4:39 PM, Peter Eisentraut pete...@gmx.net wrote: On fre, 2009-12-18 at 11:51 -0500, Robert Haas wrote: On Fri, Dec 18, 2009 at 11:32 AM, David E. Wheeler da...@kineticode.com wrote: On Dec 18, 2009, at 4:49 AM, Peter Eisentraut wrote: Should we create a json type

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Andrew Dunstan
Robert Haas wrote: On Fri, Dec 18, 2009 at 3:00 PM, Tom Lane t...@sss.pgh.pa.us wrote: Alvaro Herrera alvhe...@commandprompt.com writes: Tom Lane escribió: Well, actually, now that you mention it: how much of a json type would be duplicative of the xml stuff? Would it be

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-18 Thread Robert Haas
On Fri, Dec 18, 2009 at 7:05 PM, Andrew Dunstan and...@dunslane.net wrote: One problem is that there is not a single well-defined mapping between these types.  I would say generally that XML and YAML both have more types of constructs than JSON.  The obvious ways of translating an arbitrary

[HACKERS] PATCH: Add hstore_to_json()

2009-12-16 Thread David E. Wheeler
I just realized that this was easy to do, and despite my complete lack of C skillz was able to throw this together in a couple of hours. It might be handy to some, though the possible downsides are: * No json_to_hstore(). * Leads to requests for hstore_to_yaml(), hstore_to_xml(), etc. * Andrew

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-16 Thread Robert Haas
On Wed, Dec 16, 2009 at 2:28 PM, David E. Wheeler da...@kineticode.com wrote: I just realized that this was easy to do, and despite my complete lack of C skillz was able to throw this together in a couple of hours. It might be handy to some, though the possible downsides are: * No

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-16 Thread David E. Wheeler
On Dec 16, 2009, at 2:45 PM, Robert Haas wrote: I like it. The regression tests you've added seem to cover a lot of cases that aren't really different without covering some that are probably worth trying, like multiple key/value pairs. Also, the comment in the function you've added looks

Re: [HACKERS] PATCH: Add hstore_to_json()

2009-12-16 Thread Robert Haas
On Wed, Dec 16, 2009 at 5:58 PM, David E. Wheeler da...@kineticode.com wrote: On Dec 16, 2009, at 2:45 PM, Robert Haas wrote: I like it.  The regression tests you've added seem to cover a lot of cases that aren't really different without covering some that are probably worth trying, like