Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Craig Ringer
On 08/13/2012 01:55 PM, Tom Lane wrote: Actually, given the above, what did you need value_to_json(text) for at all? Wouldn't value_to_json(anyelement) have covered it? Usability. Without the version accepting text an explicit cast to text is required to disambiguate a literal argument like

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Tom Lane
Craig Ringer writes: > As for the value_to_json crashing, works for me: > postgres=# SELECT value_to_json(42); > value_to_json > --- > 42 > (1 row) Oh, right, because there actually is support for anyelement in the underlying C function. There is not in the quote_literal case.

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Craig Ringer
On 08/13/2012 12:48 PM, Tom Lane wrote: There actually was a previous thread about this: http://archives.postgresql.org/pgsql-hackers/2012-05/msg1.php Note in particular Andrew's comment: Second, RFC 4627 is absolutely clear: a valid JSON value can only be an object or an arr

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Tom Lane
Craig Ringer writes: > Whenever I try to work with the new json types I trip over the lack of a > function to escape text to json. The attached patch against master > provides one by exposing the existing datum_to_json function to SQL. > ... > This feels basic enough that I'm wondering if there'

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Tom Lane
Craig Ringer writes: > OK, opr_sanity was failing because I added the value_to_json(text) alias > to ensure that: >value_to_json('some_literal') > worked, following the same approach as quote_literal(anyelement) and > quote_literal(text). That should be reasonable, right? No, it isn't. W

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Craig Ringer
OK, opr_sanity was failing because I added the value_to_json(text) alias to ensure that: value_to_json('some_literal') worked, following the same approach as quote_literal(anyelement) and quote_literal(text). That should be reasonable, right? The comments on the affected check in opr_sanity

Re: [HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Craig Ringer
Whoops. It actually looks like the posted patch muffed up opr_sanity checks. I'm totally new to pg_proc.h wrangling so I'm not sure why yet, looking. Sorry, not sure how I missed that. I'll follow up shortly. -- Craig Ringer -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.or

[HACKERS] PATCH: Implement value_to_json for single-datum conversion

2012-08-12 Thread Craig Ringer
Hi all Whenever I try to work with the new json types I trip over the lack of a function to escape text to json. The attached patch against master provides one by exposing the existing datum_to_json function to SQL. I've used the name value_to_json, but I'm not sure it's necessarily the right