pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Steve Atkins <steve@blighty.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Sun, 20 Oct 2019 10:13:04 +0100
Message-ID: <5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com> (raw)
In-Reply-To: <CAAOiGNx=xxhPxfFwa71iwfqLw7Ns-mdMVjs1AnHq0z=fH4sd3w@mail.gmail.com>
References: <CAAOiGNwUsgM-UBqsJH_mriCFr-JCPxD+pQoXNvyOEQPc+YHQRQ@mail.gmail.com>
	<20191018215018.GB56427@elch.exwg.net>
	<CAKFQuwZ2w5D1yJ9vaexiR8kbqOyxbzKwo2hsbi74ruVfFiNe-g@mail.gmail.com>
	<CAAOiGNyc=g3CvazQ3degiUpzrLiF2P-JyE++BMj5Mxe6K+XARQ@mail.gmail.com>
	<ec60858c-f01c-8103-a039-415f2ef87d04@aklaver.com>
	<CAAOiGNzvaExLy_u-D0-8Xj_wO2Od6cexrReZcFugYvAMNXATnA@mail.gmail.com>
	<7299c63c-fcdc-20fc-c955-4cd330cc4580@aklaver.com>
	<CAAOiGNzRM=Vpw8W1QM2cd7NUr0BQX_Oyb0A+SQaBNdVMH=_0tA@mail.gmail.com>
	<CAFj8pRBeetjReCxvb+NkLoY_521J5wELjya12eisz6rnZi87nQ@mail.gmail.com>
	<CAKFQuwZRLKwfu4Tz3V68UYmvRb_6HKKTU7NJ5S_ZLmHq5+00=g@mail.gmail.com>
	<CAFj8pRDCtcP8V2py48yoqOn3fv9am4awd5kzbJ6ohaLgdh7cUw@mail.gmail.com>
	<CAAOiGNx=xxhPxfFwa71iwfqLw7Ns-mdMVjs1AnHq0z=fH4sd3w@mail.gmail.com>


On 19/10/2019 07:52, Ariadne Conill wrote:
>
> I would say that any thing like
>
> update whatever set column=jsonb_set(column, '{foo}', NULL)
>
> should throw an exception.  It should do, literally, *anything* else
> but blank that column.

steve=# create table foo (bar jsonb not null);
CREATE TABLE
steve=# insert into foo (bar) values ('{"a":"b"}');
INSERT 0 1
steve=# update foo set bar = jsonb_set(bar, '{foo}', NULL);
ERROR:  null value in column "bar" violates not-null constraint
DETAIL:  Failing row contains (null).
steve=# update foo set bar = jsonb_set(bar, '{foo}', 'null'::jsonb);
UPDATE 1

I don't see any behaviour that's particularly surprising there? Though I 
understand how an app developer who's light on SQL might get it wrong - 
and I've made similar mistakes in schema upgrade scripts without 
involving jsonb.

Cheers,
   Steve






view thread (83+ messages)  latest in thread

Message-ID: <5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com>
Permalink:  ../5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com/
Also on:    postgresql.org/message-id/5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.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-general@postgresql.org
  Cc: steve@blighty.com
  Subject: Re: jsonb_set() strictness considered harmful to data
  In-Reply-To: <5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com>
  References: <CAAOiGNwUsgM-UBqsJH_mriCFr-JCPxD+pQoXNvyOEQPc+YHQRQ@mail.gmail.com> <20191018215018.GB56427@elch.exwg.net> <CAKFQuwZ2w5D1yJ9vaexiR8kbqOyxbzKwo2hsbi74ruVfFiNe-g@mail.gmail.com> <CAAOiGNyc=g3CvazQ3degiUpzrLiF2P-JyE++BMj5Mxe6K+XARQ@mail.gmail.com> <ec60858c-f01c-8103-a039-415f2ef87d04@aklaver.com> <CAAOiGNzvaExLy_u-D0-8Xj_wO2Od6cexrReZcFugYvAMNXATnA@mail.gmail.com> <7299c63c-fcdc-20fc-c955-4cd330cc4580@aklaver.com> <CAAOiGNzRM=Vpw8W1QM2cd7NUr0BQX_Oyb0A+SQaBNdVMH=_0tA@mail.gmail.com> <CAFj8pRBeetjReCxvb+NkLoY_521J5wELjya12eisz6rnZi87nQ@mail.gmail.com> <CAKFQuwZRLKwfu4Tz3V68UYmvRb_6HKKTU7NJ5S_ZLmHq5+00=g@mail.gmail.com> <CAFj8pRDCtcP8V2py48yoqOn3fv9am4awd5kzbJ6ohaLgdh7cUw@mail.gmail.com> <CAAOiGNx=xxhPxfFwa71iwfqLw7Ns-mdMVjs1AnHq0z=fH4sd3w@mail.gmail.com> <5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.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