Re: Why does jsonb_set() remove non-mentioned keys? - Mailing list pgsql-general

From David G. Johnston
Subject Re: Why does jsonb_set() remove non-mentioned keys?
Date
Msg-id CAKFQuwbb7=ciX-MXeDyAk1H4WFNQZXpQh82eby8ExY4epYT0gQ@mail.gmail.com
Whole thread Raw
In response to Re: Why does jsonb_set() remove non-mentioned keys?  (Gianni Ceccarelli <dakkar@thenautilus.net>)
Responses Re: Why does jsonb_set() remove non-mentioned keys?  ("David G. Johnston" <david.g.johnston@gmail.com>)
Re: Why does jsonb_set() remove non-mentioned keys?  (Gianni Ceccarelli <dakkar@thenautilus.net>)
List pgsql-general
On Thursday, July 4, 2019, Gianni Ceccarelli <dakkar@thenautilus.net> wrote:
Some experimentation:

> \pset null '((null))'

> select jsonb_set('{"foo":1}'::jsonb,'{bar}','null'::jsonb,true);
┌─────────────────────────┐
│        jsonb_set        │
├─────────────────────────┤
│ {"bar": null, "foo": 1} │
└─────────────────────────┘

No SQL null, ok 


> select jsonb_set('{"foo":1}'::jsonb,'{bar}',to_jsonb(null::text),true);
┌───────────┐
│ jsonb_set │
├───────────┤
│ ((null))  │
└───────────┘

Sql null poisons the expression and so sql null is the result
 

That's a bit weird already. Also:

> select null::jsonb;
┌──────────┐
│  jsonb   │
├──────────┤
│ ((null)) │
└──────────┘


Sql null
 
> select 'null'::jsonb;
┌───────┐
│ jsonb │
├───────┤
│ null  │
└───────┘


Json null
 
> select to_jsonb(null::int);
┌──────────┐
│ to_jsonb │
├──────────┤
│ ((null)) │
└──────────┘


Sql null poisons the function call which immediately returns sql null
 
> select to_jsonb('null'::text);
┌──────────┐
│ to_jsonb │
├──────────┤
│ "null"   │
└──────────┘


Json null
 
I'm sharing Thomas's confusion…


Sql null and json null are represented differently; strict functions with sql null inputs yield sql null output without even executing the function

David J. 

pgsql-general by date:

Previous
From: Gianni Ceccarelli
Date:
Subject: Re: Why does jsonb_set() remove non-mentioned keys?
Next
From: Adrian Klaver
Date:
Subject: Re: Converting to identity columns with domains on PK columns