Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1f2yCo-0003Jz-Ny for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Apr 2018 12:04:58 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1f2yCn-0007EW-OS for pgsql-bugs@arkaria.postgresql.org; Mon, 02 Apr 2018 12:04:57 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1f2yCn-0007EN-CM for pgsql-bugs@lists.postgresql.org; Mon, 02 Apr 2018 12:04:57 +0000 Received: from mail-it0-x241.google.com ([2607:f8b0:4001:c0b::241]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from <9erthalion6@gmail.com>) id 1f2yCk-0007h5-8e for pgsql-bugs@lists.postgresql.org; Mon, 02 Apr 2018 12:04:56 +0000 Received: by mail-it0-x241.google.com with SMTP id r19-v6so18573165itc.0 for ; Mon, 02 Apr 2018 05:04:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=1KbjoZAGZEBnCtMeAwka+aWDzc3teHKZbdKV7OvqMYI=; b=c5Y22rTsIaknS98tgKV7iAFm7YJbNwoNdgT5CDE0iUx0k4BufHzH85Ft6CTmVz+8Bc NP8vleZel7bTmLKSQlnGUuJ92Jb5v9sc2KF+T7cuQuFSCNa9YpNIMwBNefkA3ortGXbf 2+px6wI6iwhgbvR+tFUqDv0QeGLE2cxYOfU2xEpCLlmdFm2q0/ZijSSkBYlzs1+dNS3O zM42aAVFCuK/L+lrMnFky83dFs9WzfLNy14TI/5G6DuAmo4sz+6LyyTtzRUItaNDN1FO +hcDzXKnPZm8f5ismIIoSG6gJqYS+2UE4zi5e1jGTsl83nC0f8A23FgDWwDJflqjucgS Cyhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=1KbjoZAGZEBnCtMeAwka+aWDzc3teHKZbdKV7OvqMYI=; b=uXtMfFe2cdq18hXKsk8QF3Y0YEKuCoZsRTC6Nqp6Uo/x7tzc3LOZMw0qUIGMk/CIvZ JQe/Jb9eW6r7UEe5nkPsFSqZTDGiHni93J84TAaUOg7OCSOAuF0EhR0uSQ8SZgZfXmIH Baw8WwRo8XhBPRekc6wx13Kps6opgoXqhsxQ4+vGwhy1lAhKDm3QE55ZjxF975OyoAna P7KgPyWlMbTRhqfNdaEl66hdY/4FwlmcxZQb7wJfCae80GqIXjl1Pdx38qd20hY9jbcl tbDR2ZWIDpryZ9ldDgOt47KvGyAwN1hbanKDuLKr6wotp2XSnIng6WXCE7bXDwCiLCf4 EpsQ== X-Gm-Message-State: ALQs6tD4SPuAeI0n+wzNhkKztG+w+wnR16El3gCQT/gbNmbnnLj3uPVR W8RHFyxJbDV+KajCz1Q8nDHFYbO6Gd/yUu84ZgZ0aA== X-Google-Smtp-Source: AIpwx4/oLwJNy+KOCFg6R5kXCOCmsqzGmBtQp0kRK4zaexTEWZOi/3g9oKWNbcFxw26I1Fz1X+/TTHqG3ljSClhtXHM= X-Received: by 2002:a24:428f:: with SMTP id i137-v6mr747516itb.33.1522670692947; Mon, 02 Apr 2018 05:04:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.2.43.37 with HTTP; Mon, 2 Apr 2018 05:04:12 -0700 (PDT) In-Reply-To: <152266540508.1442.16790414733320933622@wrigleys.postgresql.org> References: <152266540508.1442.16790414733320933622@wrigleys.postgresql.org> From: Dmitry Dolgov <9erthalion6@gmail.com> Date: Mon, 2 Apr 2018 14:04:12 +0200 Message-ID: Subject: Re: BUG #15140: Incorrect jsonb_set behavoir To: "Ivan E. Panchenko" , pgsql-bugs@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On 2 April 2018 at 12:36, PG Bug reporting form = wrote: > The following bug has been logged on the website: > > Bug reference: 15140 > Logged by: Ivan Panchenko > Email address: i.panchenko@postgrespro.ru > PostgreSQL version: 10.3 > Operating system: any > Description: > > First. Impossible to create a nested structure for a path with more than = one > new keys. > > postgres =3D> select jsonb_set('{}'::jsonb, array['x', 'y'], > to_jsonb(1::text), true); > jsonb_set > ----------- > {} > (1 =D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0) > > Expected {"x": { "y" : "1" }} > > Second. Setting a NULL value nullifies the whole JSON > > postgres=3D> select jsonb_set('{}'::jsonb, array['x'], null, true); > jsonb_insert > -------------- > > (1 =D1=81=D1=82=D1=80=D0=BE=D0=BA=D0=B0) > > Expected { "x" : null } As far as I remember, these are not really bugs, but documented behavior. About the first one, here is [1]: All the items of the path parameter of jsonb_set as well as jsonb_inser= t except the last item must be present in the target. If create_missing i= s false, all items of the path parameter of jsonb_set must be present. If these conditions are not met the target is returned unchanged. Although I agree this can be confusing, and we may want to change this. About the second one, `jsonb_set` is defined as a strict function, which me= ans `null` arguments will produce null as a result. To avoid this you can do: =3D# select jsonb_set('{}'::jsonb, array['x'], 'null', true); jsonb_set ------------- {"x": null} (1 row) 1: https://www.postgresql.org/docs/devel/static/functions-json.html