pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Greg Hazel <ghazel@gmail.com>
To: Craig Ringer <ringerc@ringerc.id.au>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7620: array_to_json doesn't support heterogeneous arrays
Date: Wed, 24 Oct 2012 08:46:08 -0700
Message-ID: <F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com> (raw)
In-Reply-To: <50879711.6020209@ringerc.id.au>
References: <E1TQnxe-0002WI-DP@wrigleys.postgresql.org>
	<50879711.6020209@ringerc.id.au>


On Oct 24, 2012, at 12:21 AM, Craig Ringer <ringerc@ringerc.id.au> wrote:

> On 10/24/2012 07:32 AM, ghazel@gmail.com wrote:
>> The following bug has been logged on the website:
>> 
>> Bug reference:      7620
>> Logged by:          Greg Hazel
>> Email address:      ghazel@gmail.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.
> 
> The issue here isn't array_to_json, it's PostgreSQL arrays.
> 
> 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.
> 
> 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:
> 


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





view thread (10+ messages)  latest in thread

Message-ID: <F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com>
Permalink:  ../F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com/
Also on:    postgresql.org/message-id/F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: ghazel@gmail.com, ringerc@ringerc.id.au
  Subject: Re: BUG #7620: array_to_json doesn't support heterogeneous arrays
  In-Reply-To: <F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com>
  References: <E1TQnxe-0002WI-DP@wrigleys.postgresql.org> <50879711.6020209@ringerc.id.au> <F1B8C7A1-C22E-457A-A470-E938DD347B28@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox