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 1iLrdY-0004Vw-Cu for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 16:31:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLrdW-0001Fl-NO for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 16:31:26 +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 1iLrdW-0001Fd-AX for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 16:31:26 +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 1iLrdP-0005C5-GO for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 16:31:24 +0000 Received: by mail-wm1-x344.google.com with SMTP id 14so2179566wmu.0 for ; Sat, 19 Oct 2019 09:31:19 -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:in-reply-to:user-agent; bh=HaUg8BSEudaShg2LbeBqwMnUYO20xnus2waGelOWgOg=; b=jXcPu1EEhH3wJ/sUvq40ehVtWkM3k5bT9FrafaNunxq/zxFnA5c/cZXiKVC67ErDOw EhuwSSqijEotMBPBMGHe9fiTz0p6VipUJy9o8g807htcCk7XuZj8x1z+s6/KLDSC1lzd eNCskruHgENqZ1sSNVH1REdpIb54lp5X/vc3dg+D8UjND+Jz/qPwvETPJILYtNj4+HwS yDrt+oRyLShYD3qNW2cpBRRXMhwc4Acc/ybHE+aa2r0Uw155h3Ed0ZK67PuC2tNy8f/x bkHydBU2nQ/KDdBwfTq0DzFwKYGuCNweGzc484RL+Vopd/euCALEtbEWP2iVUUgdsFHn fxmg== 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:in-reply-to:user-agent; bh=HaUg8BSEudaShg2LbeBqwMnUYO20xnus2waGelOWgOg=; b=b+QR/PMp/GS6y93ee8uSHApBxCrM9qWrsVNn3VDnfGGLD230CsHbBbdJMbCDgXEloO 7js1eIE0je4BqJ3b/bwe3gLJ0+2jlsXKRvhwprCTBJD5iMzeIRtNQ1mUO48Oe1sB7lyt BSYXwfyySDvmM6eN4dWZ2DnU0Uq0Y8A/ovZETTZde48VaYlLVZOovh4ICzq3DWvhpSow QDw17lhvV1a7MLHRvw7xsIqFMTBjBOp4wm1upPNMjAN7lPrjTRLwRmhSlkx0/d/UYvQh S0AIwKckyi3icLeoXPQWxX4ecptQ6EgtU/Qe/9nQ3zw7kPWgZhZeXzwfrOn+iZzculc6 LyXw== X-Gm-Message-State: APjAAAVFJWOVDRaJ+WDK0SU51nYzy6u68Vi57zM+iOz91koEDdeLjLJM ynAhIJwE/72KxBXTdRw+UtfpNA== X-Google-Smtp-Source: APXvYqyKkgx4BtKGNM7ige1mgK7Kizw0KvuhUcx8zplonoWrTXo3qB9Tk2KJrnEkk63TP2Hga0W49g== X-Received: by 2002:a1c:e10a:: with SMTP id y10mr12136945wmg.29.1571502677820; Sat, 19 Oct 2019 09:31:17 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id a17sm4864001wmb.8.2019.10.19.09.31.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 09:31:17 -0700 (PDT) Date: Sat, 19 Oct 2019 18:31:15 +0200 From: Tomas Vondra To: Stephen Frost Cc: Dmitry Dolgov <9erthalion6@gmail.com>, Ariadne Conill , Adrian Klaver , "David G. Johnston" , Christoph Moench-Tegeder , "pgsql-generallists.postgresql.org" , feld@freebsd.org Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191019163115.gg46ql7flpxr7ryn@development> References: <20191018215018.GB56427@elch.exwg.net> <20191018235159.GG6962@tamriel.snowman.net> <20191019110831.7y7d2yys5xlujqw6@development> <20191019152125.GN6962@tamriel.snowman.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20191019152125.GN6962@tamriel.snowman.net> User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Oct 19, 2019 at 11:21:26AM -0400, Stephen Frost wrote: >Greetings, > >* Dmitry Dolgov (9erthalion6@gmail.com) wrote: >> 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 don't think it makes any sense to try and extrapolate this out to >other strict functions. Functions should be strict when it makes sense >for them to be- in this case, it sounds like it doesn't really make >sense for jsonb_set to be strict, and that's where we stop it. > Yeah. I think the issue here is (partially) that other databases adopted similar functions after us, but decided to use a different behavior. It might be more natural for the users, but that does not mean we should change the other strict functions. Plus I'm not sure if SQL standard says anything about strict functions (I found nothing, but I looked only very quickly), but I'm pretty sure we can't change how basic operators change, and we translate them to function calls (e.g. 1+2 is int4pl(1,2)). >> 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). > >This seems like an entirely independent thing ... > Right. Useful, but entirely separate feature. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services