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 1iNLsP-0007jM-53 for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 19:00:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNLsN-0002uQ-R9 for pgsql-general@arkaria.postgresql.org; Wed, 23 Oct 2019 19:00:55 +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 1iNLsN-0002uJ-E1 for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 19:00:55 +0000 Received: from mail-io1-f66.google.com ([209.85.166.66]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iNLsK-0005dy-Te for pgsql-general@lists.postgresql.org; Wed, 23 Oct 2019 19:00:54 +0000 Received: by mail-io1-f66.google.com with SMTP id c11so17196285iom.10 for ; Wed, 23 Oct 2019 12:00:52 -0700 (PDT) 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:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=lytg1lLmgBgsBuGzEWSYy9hEy/wmRrfUXM+8bqE0+7o=; b=GeoRXByxZe+O52SYSUonzKzegzvxiuxpaMEZCoYSj8yhldqfsYHBzN79Etm96CNvCh cgf34/8jFP4W0qrwVd+sudNG0IKpW7Ya9WOD9+d4g2+YAppzfg1HSEzbUmxTAAdUo+4m fG8VrpoIiBxtexuwWrnQJGy3QGks5jcnaSSS3NFOF4Q9Hk8Z6pX01ekG3WSsmGgiazJC nI/kayG5X7LUU43/ask+4XGFhRSI3GnPlGFdi0EN0oHjjZM1l4R+YY0Np+RrrBvl5PWt O2wysZA8AJUxaPlEGnGgdxPuK8hnHEybke3l4QPxRptNj8VxCkwEyHMHb51uKLtQh8f1 Ua0Q== X-Gm-Message-State: APjAAAWKYXx+BH60dQXykiVFgbrEW0ulZ5Mqyo3X4GBTxwNfARxCEkIc fwyA0ZGCVto2XfRLbA+eAFZu48Nd X-Google-Smtp-Source: APXvYqwsGABJkqb/ndyOUZU2PSCaXsIu3nIM6l3gXc4ARFnDrtMpixDuNAdTi7wLYYDobtIwQMhaBQ== X-Received: by 2002:a5d:8483:: with SMTP id t3mr4948542iom.87.1571857250514; Wed, 23 Oct 2019 12:00:50 -0700 (PDT) Received: from fuji.home ([65.183.81.59]) by smtp.gmail.com with ESMTPSA id p19sm4404468ili.56.2019.10.23.12.00.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Oct 2019 12:00:49 -0700 (PDT) Received: from fuji.home (fuji.home [10.1.65.222]) by fuji.home (Postfix) with ESMTPS id 5F9CD68009D for ; Wed, 23 Oct 2019 13:00:47 -0600 (MDT) From: Stuart McGraw Subject: Re: jsonb_set() strictness considered harmful to data To: "pgsql-generallists.postgresql.org" References: <20191019161851.v7dwloiiav5yrpwu@development> <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191022225513.GA12201@hjp.at> Message-ID: <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com> Date: Wed, 23 Oct 2019 13:00:47 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/23/19 5:42 AM, Laurenz Albe wrote: > David G. Johnston wrote: >> Now if only the vast majority of users could have and keep this level of understanding >> in mind while writing complex queries so that they remember to always add protections >> to compensate for the unique design decision that SQL has taken here... > > You can only say that if you don't understand NULL (you wouldn't be alone). > If I modify a JSON with an unknown value, the result is unknown. > This seems very intuitive to me. Would you expect modifying an array value with an unknown would result in the entire array being unknown? > One could argue that whoever uses SQL should understand SQL. > > But I believe that it is reasonable to suppose that many people who > use JSON in the database are more savvy with JSON than with SQL > (they might not have chosen JSON otherwise), so I agree that it makes > sense to change this particular behavior. > > Yours, > Laurenz Albe That (generally) SQL NULL results in NULL for any operation has been brought up multiple times in this thread, including above, as a rationale for the current jsonb behavior. I don't think it is a valid argument. When examples are given, they typically are with scalar values where such behavior makes sense: the resulting scalar value has to be NULL or non-NULL, it can't be both. It is less sensible with compound values where the rule can apply to individual scalar components. And indeed that is what Postgresql does for another compound type: # select array_replace(array[1,2,3],2,NULL); array_replace --------------- {1,NULL,3} The returned value is not NULL. Why the inconsistency between the array type and json type? Are there any cases other than json where the entire compound value is set to NULL as a result of one of its components being NULL?