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 1iNrXA-0006hp-FK for pgsql-general@arkaria.postgresql.org; Fri, 25 Oct 2019 04:49:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNrX9-0003Hx-6g for pgsql-general@arkaria.postgresql.org; Fri, 25 Oct 2019 04:49:07 +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 1iNrX8-0003Hq-Sn for pgsql-general@lists.postgresql.org; Fri, 25 Oct 2019 04:49:06 +0000 Received: from mail-il1-f172.google.com ([209.85.166.172]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNrX6-00013T-Cd for pgsql-general@lists.postgresql.org; Fri, 25 Oct 2019 04:49:06 +0000 Received: by mail-il1-f172.google.com with SMTP id t5so671708ilh.10 for ; Thu, 24 Oct 2019 21:49:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ycmZpALN5vYq+ZAv9mUOSNCCWn1wllDk3iMW2a/5tFA=; b=iONdPtirqkeQv7aL+wSAZp5gs5BV4/XYzg06DB309Sj0lf5QrpHD1CrxsigypAxfpN iRpEvqvueGJHk8RevdDZJCvYqnzpMywY6NeDonwrSjw+ONQWqC2X4S2eWjIe65fNpVwI ZtG506Ow64aOsX0wmCvrdZtqxzLgpxcnC510xKUuDdPmgDxxqNVU/yrQ3bOPTy+rPHNZ 84Z1HUPi8cHRdmIabGYpHyeaapjQqrwGeYX2ipAEg0buKpWryv6NtioenkkJmI8fG3f8 REqpv9612okxlzDdPao2Tto7F+Y5r7TWq/kFpXbX00+JOmWE+CyfsYIeM5y5FtB6cLwt 1lzw== X-Gm-Message-State: APjAAAX4Yu5Rc6Je5ZO471hMz6Di/OCVbZGN+US+vyz1vRJUhN3YUKbD KqjFv/ruOA+AGDxkJoulRQPoxDre X-Google-Smtp-Source: APXvYqw+E7RzNYSymK+m91Y4uKSZ3Pv7xE8tv/JWjAYtGAyJLENzvqUvqNDB8m1CIw27wjlFGblwcg== X-Received: by 2002:a92:c524:: with SMTP id m4mr342225ili.210.1571978942083; Thu, 24 Oct 2019 21:49:02 -0700 (PDT) Received: from fuji.home ([65.183.81.59]) by smtp.gmail.com with ESMTPSA id y23sm165472iof.51.2019.10.24.21.49.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 21:49:01 -0700 (PDT) Received: from fuji.home (fuji.home [10.1.65.222]) by fuji.home (Postfix) with ESMTPS id D3791680163 for ; Thu, 24 Oct 2019 22:48:58 -0600 (MDT) Subject: Re: jsonb_set() strictness considered harmful to data Cc: "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> <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com> <20073.1571948278@sss.pgh.pa.us> From: Stuart McGraw Message-ID: <39c43da4-1c1e-ef42-9f47-8044334dc44b@mtneva.com> Date: Thu, 24 Oct 2019 22:48:58 -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: <20073.1571948278@sss.pgh.pa.us> 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/24/19 2:17 PM, Tom Lane wrote: > Laurenz Albe writes: >> On Wed, 2019-10-23 at 13:00 -0600, Stuart McGraw wrote: >>> It is less sensible with compound values where the rule can apply to >>> individual scalar components. > > I agree that JSON can sensibly be viewed as a composite value, but ... > >>> 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? > > ... the flaw in this argument is that the array element is actually > a SQL NULL when we're done. To do something similar in the JSON case, > we have to translate SQL NULL to JSON null, and that's cheating to > some extent. They're not the same thing (and I'll generally resist > proposals to, say, make SELECT 'null'::json IS NULL return true). > > Maybe it's okay to make this case work like that, but don't be too > high and mighty about it being logically clean; it isn't. > > regards, tom lane Sure, but my point was not that this was a perfect "logically clean" answer, just that the argument, which was made multiple times, that the entire result should be NULL because "that's the way SQL NULLs work" is not really right. It does seem to me that mapping NULL to "null" is likely a workable approach but that's just my uninformed opinion.