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 1iLrtM-000537-BB for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 16:47:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iLrtL-0002HB-2W for pgsql-general@arkaria.postgresql.org; Sat, 19 Oct 2019 16:47:47 +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 1iLrtK-0002Eu-NF for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 16:47:46 +0000 Received: from mail-yb1-xb41.google.com ([2607:f8b0:4864:20::b41]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iLrtH-0007AZ-0I for pgsql-general@lists.postgresql.org; Sat, 19 Oct 2019 16:47:46 +0000 Received: by mail-yb1-xb41.google.com with SMTP id q143so2786573ybg.12 for ; Sat, 19 Oct 2019 09:47:42 -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=6HaFmF3OXuOuoWMll8HtdmnAx+GTrg6oQj3kgQ4aHCc=; b=0A3BTLxEPKxeVQhA40ZZYhZbOZ3u8aVSdlBc21x9YwJ9HHaAqctIVpRLyXPIoREo9W 71YYQuzZxg5sCfaivVGJXO1BBIe6lP9u/UmYnzzzoo2/TXzi7rnWbMy3uI3J1TONOLXT gK2T+UmRF8/m5QXl4veofKIty97NjF71wYvsUb0Veogyk0kQOrR/5nI34lMSUM78/k5r w+cLRcF0GOIoekbW1V1nbiTGvVAAOPLflSvjIlujAsD0JCUBEFqOZyIvc/jqit+7euJu 4B3F+1vUrAcCUnW+396ND6ETmWkir5DTUdtvP4mp5dC8SN4QKxtgBSsIVd6J+ytVjJgQ z/pg== 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=6HaFmF3OXuOuoWMll8HtdmnAx+GTrg6oQj3kgQ4aHCc=; b=i5V1xZZjSpp5Hc8kYGPzZy3lWBFFfRaxQwONR4eVYdUFW3FaDXpYKdIvuTrc0XuJWV vUL8CynjvqkLgAT+NI92G14zQcYoJ27y12y70YtCm7lXp6AxKNDUnaoTC6IvDE3IYrHO hK7drf64B+rwizmZF8tpunLSoC4WllqD1I8l4C8vxLGsR8roTXv5TBRr3sRGUast126+ ydz/TaQQL5zN3+xAPWFEE3erKNqd5nzzD8gE1IQokvmXSuODzpjzEDRm/Atmut/FM6zZ oEhyDLnoOAaaedryJVNg/HkZqbqIHCFtKebo9M9yKVvLVn0+ZKGr9jH5CdEItJIOcQWC jSvw== X-Gm-Message-State: APjAAAUOj7fd5frgXSc3zDaxqzVoroWk0w0HxUGSH4KyipykwaZLLC0W TDuwKHOfwgrYhE4lEsN9FU3k X-Google-Smtp-Source: APXvYqwcUKQtv2HUf1qL3duGxTmlkHsA0Cvs2PllgXiTeAr3XBa2lhiwQM9ZW67ftVrzJTTpFVVthQ== X-Received: by 2002:a25:d916:: with SMTP id q22mr10853806ybg.175.1571503660881; Sat, 19 Oct 2019 09:47:40 -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 a189sm1838387ywa.58.2019.10.19.09.47.40 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 19 Oct 2019 09:47:40 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: jsonb_set() strictness considered harmful to data To: "David G. Johnston" , Tomas Vondra Cc: Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers References: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <20191019161851.v7dwloiiav5yrpwu@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 BBMBAgBCAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAUJDyV6hBYhBOQ+WEYd/Hy/RGkV pZn6f8tZ/DuBBQJcH/EVAhkBAAoJEJn6f8tZ/DuB7BEH/iDWZEbVft2m2MT6SPjARzTupt/l xLLZ/Cl6n2US2hov5+fBbnR5xvECk/YCOfG9ICvKNlpFjceqNLRKStd8cmndnI+kDw91uNM2 hpL4aJMeW65XCHvqXlOLSwv5chBpXz9NG7FMaJ+q+59sWEWjcTNmjXgkEHn53y+1pc7nSLDe cr5ZI1aB3nGXRm1SoDY5PYZkUKMykW+YBZwgcs/Q5tRaE+siN7DKbz8E628+PerwAkmHPVXN MdJFD6gs4S0gDFA8IxcyIwZU2v4By+brzcJ9Se3FK5BYxBDHtaYZxgSrJAvOUOrLIZPQTQfL TtnVs3C3JTfrxCH1ceHtnA6dRuTOwE0ETspYWQEIANGc4zQULOxhbqO2dyD51YhqCNRmm9oK Waqf+wmW4tpDe/VVcxAnNizd4LWCHfzpb5cHAtGkOPePMfzWVf6nvdF7d3eglbtf59+zG7O7 llV0xSSoFiieQBsrGvqDInXYX/4mRRXMtyhM353/tixC9RWLs1oofyYmCPPXXY7h9R7en3B8 BoVrRFcdzlIY/NFNhFGW/9dkEiGjgna2Rk6e15kln4ZvFBWUg23p93w/pqXcxY6+k/8TEk+C 4R+M6w7o2PLGOjdZ+kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaY L++LAEOqrlvm2TvqQqZRtnEAEQEAAcLAZQQYAQIADwIbDAUCXA6fpAUJDyV6xAAKCRCZ+n/L Wfw7geU4B/9vFFsVmWxerDWgNjyiK80zIPmlw/iwdUlU6FIu0JWLMg4093kvxBs7RMZV9hBq n3ekBvD4IvFsVLJrw9qzSI2FH3UeYy5WXpEs01Ppia60NOlvRDqXbryzuvfe+iYo6bVP3Ikr TPTNYL/BePUTD2DPvSI82SbGTyzuA7SJv6NRqqQDMIy1fU6KyQFLmQJp/QJyhKWzm9jWh8ee w8jVaoMY0Kbq5N7RqisEx1Lu/Iw646UphdYzQNymf+kbiU5Kf4I6DhzV8w9sie1Bo1juNj3I c5/fFJsmxljbnaDbXPcnFsur1Oo9mIHFakgWgOBMuxoWfjONiLjjLh/9+ZIqSSLX Message-ID: Date: Sat, 19 Oct 2019 12:47:39 -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: 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/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. > > > > >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. > > >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. cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services