Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMQqY-00021L-CN for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2019 06:07:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMQqV-0005kc-RB for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2019 06:07:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMQqV-0005kU-Dz for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2019 06:07:11 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iMQqS-0007Cd-DL for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2019 06:07:09 +0000 Received: by mail-wm1-x344.google.com with SMTP id q70so4563030wme.1 for ; Sun, 20 Oct 2019 23:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=rARja+BYDhh5qLPUPoZZKVFWhueyNlfMfBrH7MZvkvg=; b=RxxitDxtJNMxP2idSXOiuZlZC7PTVAkdgVrJFX2ii5eA0wLmKxadcCsb8s2SnCn4Ut IeLSjWeaS6Ws8GTIGFB2imbFf0noHBia37X3c31aRGc+bczsDdVarcS1qMvNevygTSzp FpaZw3MdGQI2SyzTTiGMFeGT8QUtY6dEWMUl4Fc+k+lq1+05xreeSX4e+hA3VhK8V9FE eLuVsdsKEGv3dr6cFhxmlhBaQkOth4bJECxouogpjhZ0CXRfMgL15M6Dluaeh+OFz0xr SePw+W4JygIO3R3NGpPX9AugT7wcml6ndy79CrnqbAOe6xaqggwv/jSEx9RIi1I1As5N XNRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=rARja+BYDhh5qLPUPoZZKVFWhueyNlfMfBrH7MZvkvg=; b=WYOTPTRn9cXjbwnyZTxmWOJ4MhhlLiucYYoBIr9cX8JahECtpvkG4/UZcOuXL2jAs7 /+atI6qXuzjBA/KA60MadGZYuuznpTtRX+LyuWWFvilC7ABbuFilkmbKDkjudLiPnP9n rzR1tYtUwKmXrt9lmtz1pWoFEVXdpjyQA6QZl1vx3PdUFIFGJWoFMjauvuHkE8374MST lNrUkOF30qwNbo/Cm0r11lTf+Uf1lOI9ukIkpE8jAVh3Ya+jEkmnMe90bkh9G6tpqVqT /g+1P41diuCzuql+q3mUe2540iJUy+EoQc1sk6FlZ861y+mf3LYlbhdMNTAjug8w7EK8 9aFQ== X-Gm-Message-State: APjAAAWzp+vqPyPnt00GGzsQcylZKKTch4XFP38vhsJN9C9SP58vM+xR TK3WRn/E7G9PmuoQYzZ5CMY/OA== X-Google-Smtp-Source: APXvYqwVLF+EKI34qcW8YOHxosoCBq3bMNR74Qt6+GTu8IdpeOWp+I5hlIkHdNHp6ULeU3xG3DA0Wg== X-Received: by 2002:a1c:7f44:: with SMTP id a65mr7209486wmd.19.1571638026695; Sun, 20 Oct 2019 23:07:06 -0700 (PDT) Received: from localhost (cst-prg-22-237.cust.vodafone.cz. [46.135.22.237]) by smtp.gmail.com with ESMTPSA id l18sm17843076wrn.48.2019.10.20.23.07.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2019 23:07:04 -0700 (PDT) Date: Mon, 21 Oct 2019 08:07:01 +0200 From: Tomas Vondra To: Andrew Dunstan Cc: "David G. Johnston" , Floris Van Nee , Ariadne Conill , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191021060701.or6a6a7lg3asixom@development> References: <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191020201839.olpuyuzixagcvvud@development> <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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 >>>> >>> > 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