pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: johann@visagie.za.net
To: pgsql-bugs@postgresql.org
Subject: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances
Date: Wed, 02 Mar 2016 08:03:10 +0000
Message-ID: <20160302080310.2629.98690@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

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



view thread (4+ messages)  latest in thread

Message-ID: <20160302080310.2629.98690@wrigleys.postgresql.org>
Permalink:  ../20160302080310.2629.98690@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160302080310.2629.98690@wrigleys.postgresql.org

 · 

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: johann@visagie.za.net
  Subject: Re: BUG #13996: json_to_record() returns non-NULL, malformed value for omitted key under some circumstances
  In-Reply-To: <20160302080310.2629.98690@wrigleys.postgresql.org>
  References: <20160302080310.2629.98690@wrigleys.postgresql.org>

* 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