> On Sat, Oct 19, 2019 at 1:08 PM Tomas Vondra <tomas.vondra@xxxxxxxxxxxxxxx> wrote: > > >Here is how other implementations handle this case: > > > >MySQL/MariaDB: > > > >select json_set('{"a":1,"b":2,"c":3}', '$.a', NULL) results in: > > {"a":null,"b":2,"c":3} > > > >Microsoft SQL Server: > > > >select json_modify('{"a":1,"b":2,"c":3}', '$.a', NULL) results in: > > {"b":2,"c":3} > > > >Both of these outcomes make sense, given the nature of JSON objects. > >I am actually more in favor of what MSSQL does however, I think that > >makes the most sense of all. > > > > I do mostly agree with this. The json[b]_set behavior seems rather > surprising, and I think I've seen a couple of cases running into exactly > this issue. I've solved that with a simple CASE, but maybe changing the > behavior would be better. That's unlikely to be back-patchable, though, > so maybe a better option is to create a non-strict wrappers. But that > does not work when the user is unaware of the behavior :-( Agree, that could be confusing. If I remember correctly, so far I've seen four or five such complains in mailing lists, but of course number of people who didn't reach out hackers is probably bigger. If we want to change it, the question is where to stop? Essentially we have: update table set data = some_func(data, some_args_with_null); where some_func happened to be jsonb_set, but could be any strict function. I wonder if in this case it makes sense to think about an alternative? For example, there is generic type subscripting patch, that allows to update a jsonb in the following way: update table set jsonb_data[key] = 'value'; It doesn't look like a function, so it's not a big deal if it will handle NULL values differently. And at the same time one can argue, that people, who are not aware about this caveat with jsonb_set and NULL values, will most likely use it due to a bit simpler syntax (more similar to some popular programming languages).