From: | Steve Atkins <steve(at)blighty(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: jsonb_set() strictness considered harmful to data |
Date: | 2019-10-20 09:13:04 |
Message-ID: | 5d3488c4-fd04-ee99-fb1e-e88cdb485238@blighty.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general pgsql-hackers |
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
From | Date | Subject | |
---|---|---|---|
Next Message | Luca Ferrari | 2019-10-20 09:35:04 | UTC-6 or UTC+6? |
Previous Message | Floris Van Nee | 2019-10-20 08:39:58 | jsonb_set() strictness considered harmful to data |
From | Date | Subject | |
---|---|---|---|
Next Message | Andreas Karlsson | 2019-10-20 11:30:33 | Re: Declaring a strict function returns not null / eval speed |
Previous Message | Floris Van Nee | 2019-10-20 08:39:58 | jsonb_set() strictness considered harmful to data |