Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ab9EJ-0007Ql-HE for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Mar 2016 16:02:27 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ab9EJ-0005lM-3p for pgsql-bugs@arkaria.postgresql.org; Wed, 02 Mar 2016 16:02:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ab1lQ-00067E-1i for pgsql-bugs@postgresql.org; Wed, 02 Mar 2016 08:04:08 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ab1lL-0007mH-GF for pgsql-bugs@postgresql.org; Wed, 02 Mar 2016 08:04:06 +0000 MIME-Version: 1.0 Subject: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances To: pgsql-bugs@postgresql.org From: johann@visagie.za.net Date: Wed, 02 Mar 2016 08:03:10 +0000 Message-ID: <20160302080310.2629.98690@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 13996 Logged by: Johann Visagie Email address: johann@visagie.za.net PostgreSQL version: 9.5.1 Operating system: OS X 10.11.3 Description: In the following call to json_to_record(), the target row format `t` specifies a text column `c` which does *not* appear as a key in the JSON object used as the function’s argument. SELECT t.* FROM json_to_record('{"a":1, "b":{"c":16, "d":2}, "x":8}'::json) AS t(a int, b json, c text, x int); By the definition of the function in section 9.15 of the manual, the statement should return a NULL value for the column `c`. This is made explicit in the second Note at the bottom of that manual page, which states i.a.: >JSON fields that do not appear in the target row type will be omitted from the output, and target columns that do not match any JSON field will simply be NULL. However, if (as in this example) another key in the JSON object — `b` in this case — refers to a nested JSON object which *does* contain a key `c`, the function returns a malformed JSON string as (text) value for column `c`: a | b | c | x ---+----------------+---------+--- 1 | {"c":16,"d":2} | {"c":16 | 8 (1 row) I have not tested whether json_ro_recordset() exhibits the same misbehaviour. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs