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 1iMK2f-0007NC-16 for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Oct 2019 22:51:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMK2c-0006EB-5k for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Oct 2019 22:51:14 +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 1iMK2b-0006E4-JC for pgsql-hackers@lists.postgresql.org; Sun, 20 Oct 2019 22:51:13 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iMK2W-0003Z9-6i for pgsql-hackers@lists.postgresql.org; Sun, 20 Oct 2019 22:51:12 +0000 Received: by mail-yb1-xb41.google.com with SMTP id z125so3489419ybc.4 for ; Sun, 20 Oct 2019 15:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=8yyp1VCtPYyrsr2GJUFuHaEiViiBwpM3d9g6g1tTw/4=; b=q3Oepq38Q6xO3eOaOb3eEeoAhHSyEUdAMFt0wIkM7wV/EEwRkyFV/VDqO91OCnBj5S 9bdCjNxkmJRYJfX8ovyf1LP67bt4pXRNSZvOoEfGxSoh4LbzA6q+D4Z96iW6BMvRgRbj rEaTHkvhXLhbaHoUNMinAVsX2WYDPNBPN8AEHMVtVJwKQJOiIXBpmySPopA69AnXAqbd Qy5wK+ij9btkYRKrzLnHj7Bf5HSaJs4K7lG2YWeCHr4A5okCtIz1c+CDBL+9k2zjVyOX vV5V8LZicrADKnya+Sf3GDW/JIqpYjRG/xaoiH3q+GNvTBROYCGPTwJo2mnqV80X2rk5 Dc1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=8yyp1VCtPYyrsr2GJUFuHaEiViiBwpM3d9g6g1tTw/4=; b=SYIlVjKJ7j/xQwjfGfAvBXIdtcxGpW58HAfP9csNIks3aGz/ifJyLZyt8otAHyagWb BU1ey/K3mzqFprgXq5XTFeFtSv+jmZGjCLdcxGyxkt58x0EMQGRI+23lUhRLic6QJAob KlNYa5m62pQ9e8toLkXi7yLL/O2ezhy9uhlYuOGBVSoihO8Btw7zP3EOZRnFh1lnVDUc b3692OUB7VFPuW1F9lOE0dIO3OPQhpGtOoMouzN2WFWAmtoEApjAATNnvD5xB9OG1dVf a3qe7Y6UtBl4AqoQD03qvAEzmN/nvBkKq3gg6r7nPSHcyzXutvwkoDfhxhkkYNJdIXLu oOeQ== X-Gm-Message-State: APjAAAWwEN+Ys5M6eSGqcl5qWqbCU2odRDCZDo01od/NA1tV/A8QQvfk 381fOaaw5ZCtdKkpxJ3rP1qDoTUW1ueTlzRqZNUpKoDxq+eCle3t+33g+is0ysmq49BD6un8R0C zipZGOfcvaHN2TYuWsgm6Z/c88Z/Z77EZeFXAG87HMqZ6n9rFOPkTijyIOkJ+Ae0gwIS86BtdFd 4hwkOXyaOomZPEuUEdJsVNDWQ= X-Google-Smtp-Source: APXvYqzO69F1N54pQtLM1vL839i1HUcDHJ+t6AqWwI0q5H5+hOkcJWf+Fp8scqN5FX3jwOdYEk/BZg== X-Received: by 2002:a25:5f01:: with SMTP id t1mr13812601ybb.119.1571611866655; Sun, 20 Oct 2019 15:51:06 -0700 (PDT) Received: from [192.168.10.146] (99-10-92-30.lightspeed.rlghnc.sbcglobal.net. [99.10.92.30]) by smtp.gmail.com with ESMTPSA id o128sm3322705ywc.90.2019.10.20.15.51.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Oct 2019 15:51:06 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: jsonb_set() strictness considered harmful to data To: Tomas Vondra Cc: "David G. Johnston" , Floris Van Nee , Ariadne Conill , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers References: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <20191019161851.v7dwloiiav5yrpwu@development> <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191020201839.olpuyuzixagcvvud@development> Openpgp: preference=signencrypt Autocrypt: addr=andrew.dunstan@2ndQuadrant.com; prefer-encrypt=mutual; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNL0FuZHJldyBEdW5zdGFuIDxhbmRyZXcuZHVuc3RhbkAybmRRdWFkcmFudC5jb20+wsCY BBMBAgBCAhsDBgsJCAcDAgYVCAIJC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bq5N7RqisEx1Lu/Iw646UphdYzQNymf+kbiU5Kf4I6DhzV8w9sie1Bo1juNj3I c5/fFJsmxljbnaDbXPcnFsur1Oo9mIHFakgWgOBMuxoWfjONiLjjLh/9+ZIqSSLX Message-ID: <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com> Date: Sun, 20 Oct 2019 18:51:05 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20191020201839.olpuyuzixagcvvud@development> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. > > 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. > > 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. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services