Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHkeI-0002fs-Hd for pgsql-general@arkaria.postgresql.org; Thu, 23 Nov 2017 06:06:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHkeI-0000BW-4P for pgsql-general@arkaria.postgresql.org; Thu, 23 Nov 2017 06:06:10 +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.84_2) (envelope-from ) id 1eHkeH-0000BH-N8 for pgsql-general@lists.postgresql.org; Thu, 23 Nov 2017 06:06:09 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eHkeE-0002qD-Cb for pgsql-general@lists.postgresql.org; Thu, 23 Nov 2017 06:06:08 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id 7956521C1D0F for ; Thu, 23 Nov 2017 09:06:03 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from [192.168.1.142] (ppp109-252-62-180.pppoe.spdop.ru [109.252.62.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id 42F2D21C1692 for ; Thu, 23 Nov 2017 09:06:03 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1511417163; bh=kKbJzYSvtCLOaK4D39nP41VxLKl8csx76C5B4F42GRs=; h=Subject:To:References:From:Date:In-Reply-To; b=fMiji8FE3jDa5BqInNRSjPHaFz+Q22hud3tEreVbqX210uOkhZ3EeZtJHT/xnQMn5 hX1N5yoJrpc6GgJP+YeCrTS+gZ/mBqm/GVjsupUT8FFDfryeyxseSkF83yucofdCcm jzVMOxFh2WhWwj1LbFbjGrcOLoZWwQUAjKD/LR94= Subject: Re: update field in jsonb To: pgsql-general@lists.postgresql.org References: <9a1c3dd0-39f0-7da2-61b6-58621a89a288@tigernassau.com> From: "Ivan E. Panchenko" Message-ID: Date: Thu, 23 Nov 2017 09:06:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <9a1c3dd0-39f0-7da2-61b6-58621a89a288@tigernassau.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 23.11.2017 04:45, support-tiger пишет: > is there a way to update a single field in jsonb without replacing the > entire json document - couldn't find an example > > for example > > create table test (id primary key, data jsonb); > > insert into test ({"name":"bill", "age":29}); > >  ?? update test   set data->age = 30 > > When a record in PostgeSQL is UPDATEd, its new version is created. So such partial JSON update would be not more than some syntax sugar. That is why it is not yet implemented, though plans for that exist. Now you have to do something like: UPDATE test SET data = jsonb_set(data, ARRAY['age'], to_jsonb(30)) WHERE ..