Re: bug in json_to_record with arrays

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Josh Berkus <josh(at)agliodbs(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: bug in json_to_record with arrays
Date: 2014-11-26 20:48:42
Message-ID: 25904.1417034922@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Josh Berkus <josh(at)agliodbs(dot)com> writes:
> On 11/26/2014 11:54 AM, Josh Berkus wrote:
>> Tested on 9.4b3, 9.4rc1, 9.5devel
>>
>> select * from json_to_record('
>> {"id":1,"val":"josh","valry":["potter","chef","programmer"]}') as r(id
>> int, val text, valry text[]);
>>
>> ERROR: missing dimension value
>>
>> With some experimentation, I can't find any way to convert a JSON array
>> to an array field using json_to_record or json_to_recordset. I know
>> this worked back in January, though.

> Lemme take that back, it didn't work. Just checked an old devel snapshot.

> Looks like this is not intended to work, so the only bug is that we need
> a less confusing error message.

What's happening is that this string:

["potter","chef","programmer"]

is getting passed to array_in, which of course does not like it because
that's not the I/O syntax for Postgres arrays. Arguably,
populate_record_worker should be smart enough to convert somehow, but
it isn't today. Looks to me like it wouldn't succeed for the comparable
case of converting a sub-object to a Postgres composite type, either.
I'm satisfied with regarding those cases as missing features to be
added later.

As far as your request for a better error message is concerned, I'm a
bit inclined to lay the blame on array_in rather than the JSON code.
Wouldn't it be better if it said

ERROR: invalid input syntax for array: "["potter","chef","programmer"]"
DETAIL: Dimension value is missing.

which is comparable to what you'd get out of most other input functions
that were feeling indigestion?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-11-26 21:03:28 Re: 9.2 recovery/startup problems
Previous Message Tomas Vondra 2014-11-26 20:45:12 Re: BUG #12071: Stat collector went crasy (50MB/s constant writes)