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 1iMXjL-0007j2-6A for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2019 13:28:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMXjJ-0002lz-Qw for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2019 13:28:13 +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 1iMXjJ-0002lm-HI for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2019 13:28:13 +0000 Received: from mail-yw1-xc41.google.com ([2607:f8b0:4864:20::c41]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMXjG-0007N8-KG for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2019 13:28:13 +0000 Received: by mail-yw1-xc41.google.com with SMTP id w140so4898597ywd.0 for ; Mon, 21 Oct 2019 06:28:10 -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=17PXheQ7GN8wckU0wMrxXslNwPsNoJJAGq5/0f/tncU=; b=rEsvSlFvktRGH5qlTL4lFVIjrKuez4uTmauJuS3Ip9eNMYMQmv7wOI47wwTdZBmXxV X+KpA8NeAWE39NP1JgtTAm7h4Qn3cAIV1cnwIqtjNjSFGFSX84TY/eSE2EDxFzu65SIJ 3ZUkhnVngWSiwSX3DA4fLzb01jFtjYm/b6xHbh7OE7w4FYt8hBt5BfRu7i7Kz/PoUCtu U89a35bEv6UBXV/XP9BSpeMbCLa22PoU06nVUnD7ZaWPhI6tBFkc8qre4FZMVDrTQwdd pvei+kqJ504QnHA7EgkBpqnksE2Q1RIx5T8PH3c8GGhlQ4busK0C1x1N1cjLFt7kCLb2 Hz3A== 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=17PXheQ7GN8wckU0wMrxXslNwPsNoJJAGq5/0f/tncU=; b=JmjxoZF2LCnXjW/8d9QPNsEm5pykVSlJ5ulhfJxJQ5mrZtE0/yjcTTa7q5mlFi5LZ0 u5Lj3HsVTaByj8PHiPJ21KJBT1T2GB+wtRl0s4w5i9NXjgbYGuWoLmN5ZhebCluChlEQ ah/1Zc1asgCUSoQ1vXy+VhUkLHNvOL4RLAUEFSa0NLEM+zKCt+jvgaW/rrq79fb5IXUE WggL/7eCwaVpqNWReKvQmDXl63C2ieAUqE6aw9IAhrwUabjKm2ZlFdV/2UvRYUozOt9d y/A9l+hh12DxQEsx9VhHboO0XFnxzDnc+xiCH1VDuMTLHs+DWqUbb2Qq1L4OlW1uiOlZ ZiRw== X-Gm-Message-State: APjAAAUA9jp6+7KyJl8hd6UzjJDkCt4l2cWCdw2NKTT9W3kWCXS3xi+v NmQF9e7h8B67w7Ezu7OX5TN1 X-Google-Smtp-Source: APXvYqwaw8Lc1FotR4/uZvgs8JHCRy+nI5kXs4tySoP9BhR0lkjOnEtwtLtYb9ncf4+8WEp8mJ+5hQ== X-Received: by 2002:a81:578c:: with SMTP id l134mr16649489ywb.357.1571664488237; Mon, 21 Oct 2019 06:28:08 -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 f4sm1717874ywe.103.2019.10.21.06.28.07 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 21 Oct 2019 06:28:07 -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: <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> <20191021060701.or6a6a7lg3asixom@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+fBbnR5x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-5cde-8b8aaeb45d7f@2ndQuadrant.com> Date: Mon, 21 Oct 2019 09:28:06 -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: <20191021060701.or6a6a7lg3asixom@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/21/19 2:07 AM, Tomas Vondra wrote: > On Sun, Oct 20, 2019 at 06:51:05PM -0400, Andrew Dunstan wrote: >> >>> 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 > > So let's add something to the JSON funcs page  like this: Note: All the above functions except for json_build_object, json_build_array, json_to_recordset, json_populate_record, and json_populate_recordset and their jsonb equivalents are strict functions. That is, if any argument is NULL the function result will be NULL and the function won't even be called. Particular care should therefore be taken to avoid passing NULL arguments to those functions unless a NULL result is expected. This is particularly true of the jsonb_set and jsonb_insert functions. (We do have a heck of a lot of Note: sections on that page) cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services