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 1iLuNx-0002hx-Dn for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Oct 2019 19:27:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLuNw-0003Az-2G for pgsql-hackers@arkaria.postgresql.org; Sat, 19 Oct 2019 19:27:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iLuNv-0003As-Kx for pgsql-hackers@lists.postgresql.org; Sat, 19 Oct 2019 19:27:31 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iLuNr-00006H-Gd for pgsql-hackers@lists.postgresql.org; Sat, 19 Oct 2019 19:27:30 +0000 Received: by mail-wr1-x441.google.com with SMTP id o28so9578193wro.7 for ; Sat, 19 Oct 2019 12:27:27 -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=pF58Jnxc3YORwyLxtfIELshsj9w1chm4L8bZsWTswEo=; b=AqmT+atSII5iWgp9IgtR4swnLREFC4fTj6jr8vsIRwvKdWwHHODz400F091K5oS6Zd DBSBpOr+bB2HqoNz4VxYVe8JEluMwOeVihiTY1hW/AYeoVbw6Xv0tZfgzYgVLEJ3bs1Z ZH03fPmGomE9YSYmFoNgDmyq8QHiq1ugJHej++WAiWk8E9u9pEwv3lltcVcnP2CcfKRJ QtjczzLWiUvB1NocHBJTlA1X19zmOJQVmehGuPrgDW2oC4CRtaD2zJiGMqJG/cKZLu80 G9tc78eP85EoQvwJG78//E2KL+5yK74+BflObBy2Z4RW5BbnQsPbDdeE6xtnWzuvQjpB FPjw== 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=pF58Jnxc3YORwyLxtfIELshsj9w1chm4L8bZsWTswEo=; b=WmyujvBqhyd+NyOsq+NKcWHM2dmyQvFKK/fKmOuxoe23wqeL8f/1A1l4d1/GoD+BAX UWW+TC+B+XGmD5/QjtK3TL9DuXsRaDcV9O22L8JywFdg9+HLR4uUzbCakBulmDEYu9pR gk4x1s3W2/X+p6BICKGdwgyqH2YAWqfSv4t3t5dS3kEWG5l2+6DJyAyzvGD3kXYKi2Cx HhBy+vOfZXc82Q9CUlB/DUXYXpYMlUv4B1/ZKve22oaJvi84lMtLRRZ98WhlwVE7849M 1OYZmsdxIluv3EURwM0E7UocXEvN+3Xhln2lZhTyUX9qwa2q0jCR8MTVnc+XEnAYZDb8 AUzA== X-Gm-Message-State: APjAAAVo+n8Xapc0WGixaaIliIIMxeSV/gmo4ZsP+yiNJu11RnNAWAZH Dud5U3ga2G/pxZsUkXkLMF4amw== X-Google-Smtp-Source: APXvYqytUSfUwiR5ItnhoEmiWkZADnB/0vAIga4M2nLIl5N1AqWZ7065RSZvdh/bTsNvkYOy2LGRLQ== X-Received: by 2002:adf:f685:: with SMTP id v5mr9548774wrp.246.1571513245945; Sat, 19 Oct 2019 12:27:25 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id e12sm2847871wrs.49.2019.10.19.12.27.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 12:27:25 -0700 (PDT) Date: Sat, 19 Oct 2019 21:27:23 +0200 From: Tomas Vondra To: Andrew Dunstan Cc: "David G. Johnston" , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191019192723.luarxhq57qkzuncw@development> References: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <20191019161851.v7dwloiiav5yrpwu@development> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Sat, Oct 19, 2019 at 12:47:39PM -0400, Andrew Dunstan wrote: > >On 10/19/19 12:32 PM, David G. Johnston wrote: >> On Sat, Oct 19, 2019 at 9:19 AM Tomas Vondra >> > >> wrote: >> >> > >> >We invented jsonb_set() (credit to Dmitry Dolgov). And we've had it >> >since 9.5. That's five releases ago.  So it's a bit late to be >> coming to >> >us telling us it's not safe (according to your preconceptions of >> what it >> >should be doing). >> > >> >> >> There have been numerous complaints and questions about this behavior >> in those five years; and none of the responses to those defenses has >> actually made the current behavior sound beneficial but rather have >> simply said "this is how it works, deal with it". > > >I haven't seen a patch, which for most possible solutions should be >fairly simple to code. This is open source. Code speaks louder than >complaints. > IMHO that might be a bit too harsh - I'm not surprised no one sent a patch when we're repeatedly telling people "you're holding it wrong". Without a clear consensus what the "correct" behavior is, I wouldn't send a patch either. > >> >> > >> >We could change it prospectively (i.e. from release 13 on) if we >> choose. >> >But absent an actual bug (i.e. acting contrary to documented >> behaviour) >> >we do not normally backpatch such changes, especially when there is a >> >simple workaround for the perceived problem. And it's that policy >> that >> >is in large measure responsible for Postgres' deserved reputation for >> >stability. >> > >> >> Yeah. >> >> >> Agreed, this is v13 material if enough people come on board to support >> making a change. > > > >We have changed such things in the past. But maybe a new function might >be a better way to go. I haven't given it enough thought yet. > I think the #1 thing we should certainly do is explaining the behavior in the docs. > > >> >> >And if we were to change it I'm not at all sure that we should do >> it the >> >way that's suggested here, which strikes me as no more intuitive than >> >the current behaviour. Rather I think we should possibly fill in >> a json >> >null in the indicated place. >> > >> >> Not sure, but that seems rather confusing to me, because it's >> mixing SQL >> NULL and JSON null, i.e. it's not clear to me why >> >> [...] >> >> But I admit it's quite subjective. >> >> >> Providing SQL NULL to this function and asking it to do something with >> that is indeed subjective - with no obvious reasonable default, and I >> agree that "return a NULL" while possible consistent is probably the >> least useful behavior that could have been chosen.  We should never >> have allowed an SQL NULL to be an acceptable argument in the first >> place, and can reasonably safely and effectively prevent it going >> forward.  Then people will have to explicitly code what they want to >> do if their data and queries present this invalid unknown data to the >> function. >> >> > >How exactly do we prevent a NULL being passed as an argument? The only >thing we could do would be to raise an exception, I think. That seems >like a fairly ugly thing to do, I'd need a h3eck of a lot of convincing. > I don't know, but if we don't know what the "right" behavior with NULL is, is raising an exception really that ugly? regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services