Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQvI0-0007Mv-7D for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 07:22:08 +0000 Received: from mail-pb0-f46.google.com ([209.85.160.46]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TQvHt-0005FD-K0 for pgsql-bugs@postgresql.org; Wed, 24 Oct 2012 07:22:07 +0000 Received: by mail-pb0-f46.google.com with SMTP id rr4so1028472pbb.19 for ; Wed, 24 Oct 2012 00:21:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:x-enigmail-version:content-type :content-transfer-encoding:x-gm-message-state; bh=z3U/vQ2bjwwyAnnonIxVeqmfXQ0wjW4LwOnCpucvKIs=; b=WSSMNn4WpOZOL+E3FG7Vjb1k2wfjy7NPgF9fLIcd9kzLRgDWT5P/aUQaBs0WqACRAT G5L3yDiETcxh0+NUQY2W7S3prAO2hJj2qxXmFjgLmRpwqca4qk+sU5/zr/T5xkBot8qh x8Z8U/x9vgJ1QUKoMa0CkQKiEyo2OCM6YWFhLmg1UX+xR+h+ELaTcME9+Laa98UDkX15 WsdZJrrZ92xjWsGzmpd8BUnG2+PUDCCAEWPEx7FRiU0guIiekHeHYWInmjAkG97fky13 V8RJ0gTxwkV4NlFaFd6WWgvrWjfs72VqRXHUK39Et34H6KDnMpqDsvega7XOXG+rdGtp cZHA== Received: by 10.68.135.168 with SMTP id pt8mr48396584pbb.24.1351063319276; Wed, 24 Oct 2012 00:21:59 -0700 (PDT) Received: from ayaki.localdomain (124-148-78-49.dyn.iinet.net.au. [124.148.78.49]) by mx.google.com with ESMTPS id qd9sm9031909pbb.31.2012.10.24.00.21.55 (version=SSLv3 cipher=OTHER); Wed, 24 Oct 2012 00:21:57 -0700 (PDT) Message-ID: <50879711.6020209@ringerc.id.au> Date: Wed, 24 Oct 2012 15:21:53 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121016 Thunderbird/16.0.1 MIME-Version: 1.0 To: ghazel@gmail.com CC: pgsql-bugs@postgresql.org Subject: Re: BUG #7620: array_to_json doesn't support heterogeneous arrays References: In-Reply-To: X-Enigmail-Version: 1.4.5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQmb3GUhXEmAPQujhsUNYybuJc/WYIZmFHH41UWErF/QI6bTPphOvZU4m3/O1uN8AeA0ouk6 X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201210/209 X-Sequence-Number: 34509 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: regress=# SELECT ARRAY[1,'test']; ERROR: invalid input syntax for integer: "test" LINE 1: SELECT ARRAY[1,'test']; ^ Instead you want a way to take this: regress=# SELECT ROW(1,'test'); row ---------- (1,test) (1 row) and output the json: [1,"test"] instead of a json object: regress=# SELECT row_to_json(ROW(1,'test')); row_to_json ---------------------- {"f1":1,"f2":"test"} (1 row) Would a version of `row_to_json` that output a json array satisfy your needs? -- Craig Ringer