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's a reason it wasn't 
> included from the start,

There actually was a previous thread about this:
Note in particular Andrew's comment:

        Second, RFC 4627 is absolutely clear: a valid JSON value can
        only be an object or an array, so this thing about converting
        arbitrary datum values to JSON is a fantasy. If anything, we
        should adjust the JSON input routines to disallow anything else,
        rather than start to output what is not valid JSON.

It's possible he's misread the spec, but I think we ought to tread very
carefully before adding "obvious" conversions we might regret later.

> Please consider this for the 9.2 branch as well as to HEAD, as IMO it's 
> very important for basic usability of the json functionality. It applies 
> to 9.2 fine and passes "make check". I know it's late in the game,

It's several months too late for feature additions to 9.2, especially
ones that would require an initdb to install.  We can look at this for
9.3, but I'm still worried about the spec-compliance question.

                        regards, tom lane

Sent via pgsql-hackers mailing list (
To make changes to your subscription:

Reply via email to