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.92) (envelope-from ) id 1jAIUH-0006Lb-Mz for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Mar 2020 19:18:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jAIUG-0002xH-Gm for pgsql-bugs@arkaria.postgresql.org; Fri, 06 Mar 2020 19:18:20 +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 1jAIUG-0002v8-8X for pgsql-bugs@lists.postgresql.org; Fri, 06 Mar 2020 19:18:20 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jAIUD-0006E7-I6 for pgsql-bugs@lists.postgresql.org; Fri, 06 Mar 2020 19:18:19 +0000 Received: by mail-wr1-x442.google.com with SMTP id s17so2746845wrs.3 for ; Fri, 06 Mar 2020 11:18:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=xuqHwtn7IH7YCTG8XS2ho9EzMPlG/brMZ9tm+CCBThk=; b=zQfXdIlsIeCDvO9P4TJQXM4b8ld4LwjPb1Z96vT2dkwVusD0i9LW8Nx3rDwghp6tyO TQkaUzUNS6VEfW+b7tLVeAHSZCovxu0HQKA84gfs09qZdkxDGXPhymYHD4Bc8h9OS+Oj 44LlzaWkiRpVjev/iyu//0zLoLdr0LBo2mIYSEdjBDsag6BBj95AkHcsYTUTniAmCr06 4zmii/neDmSGS2C2jQOd1MfN1Fy2V0Q1voY9g0MIlrL7BXVpQdEorpUYCqiW27L4GBoT CC4yDgH7c2ZuJKnAxkW8b8X5R2EO1MoOvSgvm3qbxFoHtCuhT2SXGHrI5iBiGiBPWwhA s9mw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=xuqHwtn7IH7YCTG8XS2ho9EzMPlG/brMZ9tm+CCBThk=; b=DqI1rK8Oz1csfofGnf6wCftPpBjPTida1f7zBziG3c/Cp5FSHmoWjZyRhZxiTF8/fc GbYMhR+1fsFeSyuTb6erSuIzsplrW8tIm/9jykudoA1nMiNmYsAlPoDQgi0XnWf1bVcd 29HYAjlp2bCkdQgVMO16L98zQu8pmqzrg5DNT3Uy8wfdmVl6qdZWz9Dqy/mt0TcCl1R5 5VF3sJkqr9F9K5RK/JwhVyoU6ps0bmRV+Bzjy/u82gstbODL4my8ND4WzLNsIH5W0ssi btUSqJSvdYb0wIPNzIdzLO9rtm7npiQqcmCO6zHQ1dulp5cvTkcTPfZXLbGoy41AzZ66 E/PA== X-Gm-Message-State: ANhLgQ2pDj6JTs+rL3OV5u8kaeInaiI72PDauzgOol/wb0sz1ytHxwlU RJBUMY6r/T+y1dAegLk/L1DWxw== X-Google-Smtp-Source: ADFU+vtnuCK5DI9fGL5Mi5v2oAp1q1bBKA74jAyaO2lTTqsIHf1rzCum9Ao2dbym8iY8fTGorxDClg== X-Received: by 2002:a5d:5090:: with SMTP id a16mr2571673wrt.191.1583522296934; Fri, 06 Mar 2020 11:18:16 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id g7sm49827534wrq.21.2020.03.06.11.18.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Mar 2020 11:18:16 -0800 (PST) Date: Fri, 6 Mar 2020 20:18:14 +0100 From: Tomas Vondra To: Radics Geza Cc: pgsql-bugs@lists.postgresql.org Subject: Re: JSON array is not updated if updating with empty array Message-ID: <20200306191814.5fioiqy6ahxv6i7n@development> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Mar 06, 2020 at 06:52:43PM +0000, Radics Geza wrote: >Json column is not updated if the update is an empty array '[]'. > >UPDATE table SET "jsonbcol" = '[{"a":1}]'; >UPDATE table SET "jsonbcol = '[]' RETURNING "jsonbcol"; > >jsonbcol >------------ > [{"a": 1}] >(1 row) > >It worked in postgres 9.6, but not in 11.7 / 12.2 > >thanks! I can't reproduce this (I've tried on 12.2 and 13devel): test=# create table t (x jsonb); CREATE TABLE test=# insert into t values ('[]'); INSERT 0 1 test=# select * from t; x ---- [] (1 row) test=# UPDATE t SET "x" = '[{"a":1}]'; UPDATE 1 test=# select * from t; x ------------ [{"a": 1}] (1 row) test=# UPDATE t SET "x" = '[]'; UPDATE 1 test=# select * from t; x ---- [] (1 row) ISTM you have a typo in the second query - you're missing the closing " after the column name, so the command is not really complete/executed. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services