From: | Greg Hazel <ghazel(at)gmail(dot)com> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | pgsql-bugs(at)postgresql(dot)org |
Subject: | Re: BUG #7620: array_to_json doesn't support heterogeneous arrays |
Date: | 2012-10-24 01:18:22 |
Message-ID: | 37596181-5838-4D77-A36D-6B4215F9DCE5@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
On Oct 23, 2012, at 6:17 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
> On Tue, Oct 23, 2012 at 8:05 PM, Greg Hazel <ghazel(at)gmail(dot)com> wrote:
>> On Oct 23, 2012, at 6:03 PM, Merlin Moncure <mmoncure(at)gmail(dot)com> wrote:
>>
>>> On Tue, Oct 23, 2012 at 6:32 PM, <ghazel(at)gmail(dot)com> wrote:
>>>> The following bug has been logged on the website:
>>>>
>>>> Bug reference: 7620
>>>> Logged by: Greg Hazel
>>>> Email address: ghazel(at)gmail(dot)com
>>>> PostgreSQL version: 9.2.1
>>>> Operating system: Amazon Linux
>>>> Description:
>>>>
>>>> array_to_json(ARRAY['foo', 100, true]) complains because arrays can't have
>>>> mixed types, but json arrays can.
>>>>
>>>> So, it's not possible to form a heterogeneous json array, when this is often
>>>> desired.
>>>
>>> This is not really a bug because the feature is working as intended.
>>> Postgres arrays are homogonous so what you're asking really isn't
>>> possible. You can though use row_to_json to work around:
>>>
>>> select row_to_json(row('foo', 100, true));
>>
>> That doesn't produce the same results.
>>
>> Call it a feature request or a bug report, the postgres json support fails to make the json I need.
>
> I didn't say that it did: what it does is return a javascript object
> which is only a very little bit different from an array. For example,
> you can do jquery each() over either. I guess if you had to have an
> array, you could do it like this:
>
> array_to_json(ARRAY['foo'::text, 100::text, true::text])
Still not exactly the same json, since 100 and true would be quoted strings. I'm not parsing it with jQuery, it's a client with type expectations.
-Greg
From | Date | Subject | |
---|---|---|---|
Next Message | Craig Ringer | 2012-10-24 06:14:56 | Re: Posrgresql for Suse linux 64-bit version on OS/390 |
Previous Message | Merlin Moncure | 2012-10-24 01:17:09 | Re: BUG #7620: array_to_json doesn't support heterogeneous arrays |