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 1iNiaM-0001Jn-BO for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 19:15:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iNiaJ-0004gF-LD for pgsql-general@arkaria.postgresql.org; Thu, 24 Oct 2019 19:15: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 1iNiaJ-0004d5-9b for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 19:15:47 +0000 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iNiaG-0004JY-JG for pgsql-general@lists.postgresql.org; Thu, 24 Oct 2019 19:15:46 +0000 Received: by mail-ed1-x543.google.com with SMTP id k2so8824693edx.2 for ; Thu, 24 Oct 2019 12:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:date:in-reply-to:references:user-agent :mime-version:content-transfer-encoding; bh=A6VifachOOPluNh8xSjhE6H/d55jFq82ZFSiQKqgGos=; b=bZmmtCJv58EWyvos0dyrUjgoED246RTwML07K2HP6XHl8CkQzYPanuLsPG2Q2FNTBv TzzTXT3Fm4HcZBbTXJLWvPMcNypxHlolM4bHVnistkoLcakn82EY1ZgNVL0Dpcm9H6iL zF3pP33oaA7cgwzFl/cO1ke6CX8DoUmy/1cnUO8I0mMNkmx3bcJVBivMnzjSllixuflF yWCUjpwlZIeBmCcxqPOe3GdlOuZiyjJkZJTWNcICYlkPxZ14XgK/o74mgMI+ccSVc2Hi bnOlx/uE79oMs/NVgyjzNVi5UDWTFmyCticdBi5+zBHGG/oJXo0rKGiLmn7xX2kgqLuR Tb5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=A6VifachOOPluNh8xSjhE6H/d55jFq82ZFSiQKqgGos=; b=kbTdSlNCvnSi6vVRa8TdsvlHq5W6211ur3LGX+7V51jPg5QU5BPoM21kNPvAX2LZ7k f+vxQ34htKylL/825pwdGXWQ9VVJOqQ4OaLGi+U83q3zUXCJy2w4lGbyJe2bkNSAIJZs I15DKBLErNkWyS18OYjyQf44XXiIovSxu2tipNZYlJuwMGBcFghN2+uqx7h6PjJSCH9N nzRmefihjyfcQhA41Le6FW8jOukvS9jKXPu4zO3EO5cS1aAAyECdjC5Ia0EGwW1pJXrc Wx3OnBRDCVb/hz7R2VIFIh4tPvHZSgYSdzDBoDyCDmRl0EzNTprLAoF5TL88XdY7YJ20 z2Tw== X-Gm-Message-State: APjAAAXx8uqfV/T5zmo9WwRe3G1CUcRdaQ22knioKBjocAE+FKATAAel ti/PXIq8BiMMhEIO78ZczB2334sXLak= X-Google-Smtp-Source: APXvYqze7G2lLqT7KUucy1PVs/k8FHgs9Rb4ev2/kmSZyPDK+N6xhL8NixJLEJnoE6kinV6/1NSt6A== X-Received: by 2002:a17:906:80c1:: with SMTP id a1mr39972773ejx.37.1571944543547; Thu, 24 Oct 2019 12:15:43 -0700 (PDT) Received: from localhost.localdomain (217-149-173-174.nat.highway.telekom.at. [217.149.173.174]) by smtp.gmail.com with ESMTPSA id d22sm552383edz.1.2019.10.24.12.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 12:15:42 -0700 (PDT) Message-ID: Subject: Re: jsonb_set() strictness considered harmful to data From: Laurenz Albe To: Stuart McGraw , "pgsql-generallists.postgresql.org" Date: Thu, 24 Oct 2019 21:15:42 +0200 In-Reply-To: <04cf2b8a-1673-9060-5bd0-dce3e07ee11d@mtneva.com> 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> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.32.4 (3.32.4-1.fc30) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, 2019-10-23 at 13:00 -0600, Stuart McGraw wrote: > > 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? Hm, yes, that is less intuitive. I was viewing a JSON as an atomic value above. > > 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. > > 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? That is a good point. I agree that the behavior should be changed. Yours, Laurenz Albe -- Cybertec | https://www.cybertec-postgresql.com