Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR3A2-00018o-S1 for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 15:46:26 +0000 Received: from mail-pa0-f46.google.com ([209.85.220.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TR39w-0004eT-G1 for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 15:46:26 +0000 Received: by mail-pa0-f46.google.com with SMTP id hz1so446667pad.19 for ; Wed, 24 Oct 2012 08:46:19 -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=QoBNmJagwjJX5wSZ2dZVhh2udvXEWG/mFBMPVY2+8Ts=; b=PA6t5/Ys8lzfbYmQZRFQ7wAsremelXi9Ax3aAmHP/AiY1kOjAp2B0x/eGT7ROgTPaQ gUZZG/BRuaLlsaG+OfcthvhX8GV4ByRAtxMsLSFb4B96zNtuH9mfjxXJf+aDMtaQcQKJ dVatltpyU+gZqPYt9Db5Z9S9MSKVgFq9nnAhVPtpYlRDs1N2eRE6nUuu8zY9+/Rel4ng Zvdps62yBBfnvaEFDKUYc7R3c9q6ECnDyZVcmuwG82J2ChlrAfAC9+dDMSmWvCNta0hZ iQkbOoxcHrynhZuPSWqBNfUPeCfwHm7aGsIMOAo5rLSbnlrD50umASVDKBXihJx+hIiY JxKg== Received: by 10.68.125.133 with SMTP id mq5mr50680365pbb.138.1351093579001; Wed, 24 Oct 2012 08:46:19 -0700 (PDT) Received: from [192.168.0.6] (c-98-248-160-201.hsd1.ca.comcast.net. [98.248.160.201]) by mx.google.com with ESMTPS id bf6sm9676072pab.3.2012.10.24.08.46.09 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Oct 2012 08:46:13 -0700 (PDT) Content-Type: text/plain; charset=us-ascii 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: <50879711.6020209@ringerc.id.au> Date: Wed, 24 Oct 2012 08:46:08 -0700 Cc: pgsql-bugs@postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <50879711.6020209@ringerc.id.au> To: Craig Ringer X-Mailer: Apple Mail (2.1499) X-Pg-Spam-Score: -2.7 (--) X-Archive-Number: 201210/217 X-Sequence-Number: 34517 On Oct 24, 2012, at 12:21 AM, Craig Ringer = wrote: > On 10/24/2012 07:32 AM, ghazel@gmail.com 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 >>=20 >> array_to_json(ARRAY['foo', 100, true]) complains because arrays can't = have >> mixed types, but json arrays can. >=20 > The issue here isn't array_to_json, it's PostgreSQL arrays. >=20 > What you appear to want is a way to call row_to_json so that it = produces > a json array instead of a json object as it currently does. That way = you > could pass it a ROW() construct, composite type, or record, and have = it > output a heterogeneous JSON array. >=20 > This isn't a bug, but it's a perfectly reasonable feature request if > re-interpreted a little. It will never work with PostgreSQL arrays, > though, because the arrays themselves cannot contain mixed types: >=20 Another option that just occurred to me is a new function (say, to_json) = that converts the parameter to its json representation, with type json. Then this would be possible: select array_to_json(ARRAY[to_json('foo'), to_json(100), = to_json(true)]); -Greg