Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQpcP-0000uN-4D for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 01:18:49 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQpcH-0008CP-WA for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 01:18:48 +0000 Received: by mail-pa0-f46.google.com with SMTP id hz1so3169094pad.19 for ; Tue, 23 Oct 2012 18:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=VTwmbLEL3TCYluEJuuNwj8BUHPg7jNEbkTJM5/PcRXY=; b=qj2nR9UZh62D+7kQj9B70nZT3R6KCctP4hQMyJCsq2goKl5sgbyyj6kzPOVdD50nYC OKRlAHLFlpmvJNQen5cWGvjpOg/dTNdbtM+S7dFaHwK0VIT2BBsa/YsFddfDV/LFCqMD q3Bfcv0/3Trs7gDrsRTbmaX60K2bvAH/xYpbbA/FPJsALFo2RSfXagiIpdQeje8FglsY woYCr84PEFSKWHEnLG0lQN/QHPXPm5d1CsgI3Ytodn7UQKyVVbDtTe+nr4SjUyDEjfL+ 72P5gWnZpBA5x3eJqYZtR07mQRng6K5UJwNgeIiR8jtN7SE6u+vX90t/VE4Yd5CP9OYp XpdA== Received: by 10.68.217.104 with SMTP id ox8mr45266292pbc.35.1351041520570; Tue, 23 Oct 2012 18:18:40 -0700 (PDT) Received: from [10.1.10.22] (c-69-181-105-205.hsd1.ca.comcast.net. [69.181.105.205]) by mx.google.com with ESMTPS id tw5sm8540311pbc.48.2012.10.23.18.18.28 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 23 Oct 2012 18:18:39 -0700 (PDT) Content-Type: text/plain; charset=iso-8859-1 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: BUG #7620: array_to_json doesn't support heterogeneous arrays From: Greg Hazel In-Reply-To: Date: Tue, 23 Oct 2012 18:18:22 -0700 Cc: pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: <37596181-5838-4D77-A36D-6B4215F9DCE5@gmail.com> References: To: Merlin Moncure X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201210/215 X-Sequence-Number: 34515 On Oct 23, 2012, at 6:17 PM, Merlin Moncure wrote: > On Tue, Oct 23, 2012 at 8:05 PM, Greg Hazel wrote: >> On Oct 23, 2012, at 6:03 PM, Merlin Moncure = wrote: >>=20 >>> On Tue, Oct 23, 2012 at 6:32 PM, wrote: >>>> The following bug has been logged on the website: >>>>=20 >>>> Bug reference: 7620 >>>> Logged by: Greg Hazel >>>> Email address: ghazel@gmail.com >>>> PostgreSQL version: 9.2.1 >>>> Operating system: Amazon Linux >>>> Description: >>>>=20 >>>> array_to_json(ARRAY['foo', 100, true]) complains because arrays = can't have >>>> mixed types, but json arrays can. >>>>=20 >>>> So, it's not possible to form a heterogeneous json array, when this = is often >>>> desired. >>>=20 >>> 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: >>>=20 >>> select row_to_json(row('foo', 100, true)); >>=20 >> That doesn't produce the same results. >>=20 >> Call it a feature request or a bug report, the postgres json support = fails to make the json I need. >=20 > 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: >=20 > 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