pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tomas Vondra <tomas.vondra@2ndquadrant.com>
To: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
Cc: David G. Johnston <david.g.johnston@gmail.com>
Cc: Floris Van Nee <florisvannee@optiver.com>
Cc: Ariadne Conill <ariadne@dereferenced.org>
Cc: Mark Felder <feld@freebsd.org>
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: jsonb_set() strictness considered harmful to data
Date: Mon, 21 Oct 2019 08:07:01 +0200
Message-ID: <20191021060701.or6a6a7lg3asixom@development> (raw)
In-Reply-To: <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com>
References: <CAKFQuwa0epfqMsJ=yz8t+ASmdf5PoFXhXj=9DBpoHa2i_67nJw@mail.gmail.com>
	<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>
	<20191020201839.olpuyuzixagcvvud@development>
	<5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com>

On Sun, Oct 20, 2019 at 06:51:05PM -0400, Andrew Dunstan wrote:
>
>On 10/20/19 4:18 PM, Tomas Vondra wrote:
>> On Sun, Oct 20, 2019 at 03:48:05PM -0400, Andrew Dunstan wrote:
>>>
>>> On 10/20/19 1:14 PM, David G. Johnston wrote:
>>>> On Sun, Oct 20, 2019 at 5:31 AM Andrew Dunstan
>>>> <andrew.dunstan@2ndquadrant.com
>>>> <mailto:andrew.dunstan@2ndquadrant.com>> wrote:
>>>>
>>>>     And yet another is to
>>>>     raise an exception, which is easy to write but really punts the
>>>> issue
>>>>     back to the application programmer who will have to decide how to
>>>>     ensure
>>>>     they never pass in a NULL parameter.
>>>>
>>>>
>>>> That's kinda the point - if they never pass NULL they won't encounter
>>>> any problems but as soon as the data and their application don't see
>>>> eye-to-eye the application developer has to decide what they want to
>>>> do about it.  We are in no position to decide for them and making it
>>>> obvious they have a decision to make and implement here doesn't seem
>>>> like a improper position to take.
>>>
>>>
>>> The app dev can avoid this problem today by making sure they don't pass
>>> a NULL as the value. Or they can use a wrapper function which does that
>>> for them. So frankly this doesn't seem like much of an advance. And, as
>>> has been noted, it's not consistent with what either MySQL or MSSQL do.
>>> In general I'm not that keen on raising an exception for cases like
>>> this.
>>>
>>
>> I think the general premise of this thread is that the application
>> developer does not realize that may be necessary, because it's a bit
>> surprising behavior, particularly when having more experience with other
>> databases that behave differently. It's also pretty easy to not notice
>> this issue for a long time, resulting in significant data loss.
>>
>> Let's say you're used to the MSSQL or MySQL behavior, you migrate your
>> application to PostgreSQL or whatever - how do you find out about this
>> behavior? Users are likely to visit
>>
>>    https://www.postgresql.org/docs/12/functions-json.html
>>
>> but that says nothing about how jsonb_set works with NULL values :-(
>
>
>
>We should certainly fix that. I accept some responsibility for the omission.
>

+1

>
>>
>> You're right raising an exception may not be the "right behavior" for
>> whatever definition of "right". But I kinda agree with David that it's
>> somewhat reasonable when we don't know what the "universally correct"
>> thing is (or when there's no such thing). IMHO that's better than
>> silently discarding some of the data.
>
>
>I'm not arguing against the idea of improving the situation. But I am
>arguing against a minimal fix that will not provide much of value to a
>careful app developer. i.e. I want to do more to support app devs.
>Ideally they would not need to use wrapper functions. There will be
>plenty of situations where it is mighty inconvenient to catch an
>exception thrown by jsonb_set(). And catching exceptions can be
>expensive. You want to avoid that if possible in your
>performance-critical plpgsql code.
>

True. And AFAIK catching exceptions is not really possible in some code,
e.g. in stored procedures (because we can't do subtransactions, so no
exception blocks).

>
>>
>> FWIW I think the JSON/JSONB part of our code base is amazing, and the
>> fact that various other databases adopted something very similar over
>> the last couple of years just confirms that. And if this is the only
>> speck of dust in the API, I think that's pretty amazing.
>
>
>TY. When I first saw the SQL/JSON spec I thought I should send a request
>to the SQL standards committee for a royalty payment, since it looked so
>familiar ;-)
>

;-)

>
>>
>> I'm not sure how significant this issue actually is - it's true we got a
>> couple of complaints over the years (judging by a quick search for
>> jsonb_set and NULL in the archives), but I'm not sure that's enough to
>> justify any changes in backbranches. I'd say no, but I have no idea how
>> many people are affected by this but don't know about it ...
>>
>>
>
>No, no backpatching. As I said upthread, this isn't a bug, but it is
>arguably a POLA violation, which is why we should do something for
>release 13.
>

WFM


regards

-- 
Tomas Vondra                  http://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





view thread (83+ messages)  latest in thread

Message-ID: <20191021060701.or6a6a7lg3asixom@development>
Permalink:  ../20191021060701.or6a6a7lg3asixom@development/
Also on:    postgresql.org/message-id/20191021060701.or6a6a7lg3asixom@development

 · 

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: tomas.vondra@2ndquadrant.com, andrew.dunstan@2ndquadrant.com, david.g.johnston@gmail.com, florisvannee@optiver.com, ariadne@dereferenced.org, feld@freebsd.org, pgsql-hackers@lists.postgresql.org
  Subject: Re: jsonb_set() strictness considered harmful to data
  In-Reply-To: <20191021060701.or6a6a7lg3asixom@development>
  References: <CAKFQuwa0epfqMsJ=yz8t+ASmdf5PoFXhXj=9DBpoHa2i_67nJw@mail.gmail.com> <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> <20191020201839.olpuyuzixagcvvud@development> <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com> <20191021060701.or6a6a7lg3asixom@development>

* 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