pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Wed, 23 Oct 2019 01:01:46 +0200
Message-ID: <20191022230146.GB12201@hjp.at> (raw)
In-Reply-To: <CAKmB1PEuvXeXLNiQjRCStRKYoMEB7U9+S3bupXvHuoURiGEa6A@mail.gmail.com>
References: <a2c965cc-7d90-ed89-d50f-b2c046d4499e@2ndQuadrant.com>
	<20191019192723.luarxhq57qkzuncw@development>
	<CAAOiGNxmXSUdOzBg+7vWMzTjDELmiZi_dqGz355tKy+OgbCZpA@mail.gmail.com>
	<1571560798575.47024@Optiver.com>
	<34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com>
	<CAKFQuwbkKPYhT0S6481L7temmiN+VNrMkExsUjp6FjJnCynd5A@mail.gmail.com>
	<5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com>
	<CAKmB1PEUO4nJMODBEob4ySHYSRX1EE8TUixYf=Dg-tFHfNnt1g@mail.gmail.com>
	<20191020233115.jjy6lqd4vsyrdbbo@raf.org>
	<CAKmB1PEuvXeXLNiQjRCStRKYoMEB7U9+S3bupXvHuoURiGEa6A@mail.gmail.com>

On 2019-10-21 09:39:13 -0700, Steven Pousty wrote:
> Turning a JSON null into a SQL null  and thereby "deleting" the data
> is not the path of least surprises.

But it doesn't do that: A JSON null is perfectly fine:

wds=> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', 'null'::jsonb);
╔═════════════════════════════╗
║          jsonb_set          ║
╟─────────────────────────────╢
║ {"a": 1, "b": 2, "c": null} ║
╚═════════════════════════════╝
(1 row)


It is trying to replace a part of the JSON object with an SQL NULL (i.e.
unknown) which returns SQL NULL:

wds=> select jsonb_set('{"a": 1, "b": 2}'::jsonb, '{c}', NULL);
╔═══════════╗
║ jsonb_set ║
╟───────────╢
║ (∅)       ║
╚═══════════╝
(1 row)

        hp

-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp@hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (83+ messages)  latest in thread

Message-ID: <20191022230146.GB12201@hjp.at>
Permalink:  ../20191022230146.GB12201@hjp.at/
Also on:    postgresql.org/message-id/20191022230146.GB12201@hjp.at

 · 

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-general@postgresql.org
  Cc: hjp-pgsql@hjp.at
  Subject: Re: jsonb_set() strictness considered harmful to data
  In-Reply-To: <20191022230146.GB12201@hjp.at>
  References: <a2c965cc-7d90-ed89-d50f-b2c046d4499e@2ndQuadrant.com> <20191019192723.luarxhq57qkzuncw@development> <CAAOiGNxmXSUdOzBg+7vWMzTjDELmiZi_dqGz355tKy+OgbCZpA@mail.gmail.com> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <CAKFQuwbkKPYhT0S6481L7temmiN+VNrMkExsUjp6FjJnCynd5A@mail.gmail.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <CAKmB1PEUO4nJMODBEob4ySHYSRX1EE8TUixYf=Dg-tFHfNnt1g@mail.gmail.com> <20191020233115.jjy6lqd4vsyrdbbo@raf.org> <CAKmB1PEuvXeXLNiQjRCStRKYoMEB7U9+S3bupXvHuoURiGEa6A@mail.gmail.com> <20191022230146.GB12201@hjp.at>

* 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