Re: BUG #13533: jsonb_populate_record does not work when the value is a simple string - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #13533: jsonb_populate_record does not work when the value is a simple string
Date
Msg-id CAKFQuwar_71OGRTQxrNdmUFsYsdorpM6AcxHPhw8m+XhhWuBrA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #13533: jsonb_populate_record does not work when the value is a simple string  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Tue, Aug 4, 2015 at 5:19 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

> Paulo Vieira <paulovieira@gmail.com> writes:
> > On Mon, Aug 3, 2015 at 5:40 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> >> This does not seem like a bug, because the value of the data field is
> >> just abc, and that isn't JSON.  You'd need something more like
> >>
> >> input_data json :=3D '{"id": 1, "data": "\"abc\""}';
>
> > I'm confused. In my example the value is <double quotes>abc<double
> quotes>,
> > which is a valid json value (and not simply abc).
>
> No, the value of the field is just abc --- the quotes are JSON syntax
> decoration, they are not part of the represented value.  If we do it
> as you seem to have in mind, it would be impossible to deal sanely
> with data values that contain quotes or backslashes.
>
> =E2=80=8B
Paulo,=E2=80=8B

=E2=80=8BConsider what is stored if you define data as type text.  The resu=
ltant
value would not include the double-quotes.

The following query fails and for the same reason.

SELECT 'abc'::json

More abstractly:

'{"id": <literal number>, "data": "<literal string>"}'

The value of the <literal string> is what is going to be parsed and so it
must be whatever is needed to make the following pseudo-code succeed.

SELECT <literal string>::json;

=E2=80=8BHTH,

David J.
=E2=80=8B

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #13533: jsonb_populate_record does not work when the value is a simple string
Next
From: Tom Lane
Date:
Subject: Re: BUG #13538: REGEX non-greedy is working incorrectly (and also greedy matches fail if non-greedy is present)