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 1iMANA-0003L2-1W for pgsql-general@arkaria.postgresql.org; Sun, 20 Oct 2019 12:31:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMAN7-0005uF-Jp for pgsql-general@arkaria.postgresql.org; Sun, 20 Oct 2019 12:31:45 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMAN7-0005tY-1K for pgsql-general@lists.postgresql.org; Sun, 20 Oct 2019 12:31:45 +0000 Received: from mail-yb1-xb43.google.com ([2607:f8b0:4864:20::b43]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iMAN3-000668-T2 for pgsql-general@lists.postgresql.org; Sun, 20 Oct 2019 12:31:43 +0000 Received: by mail-yb1-xb43.google.com with SMTP id 206so3226234ybc.8 for ; Sun, 20 Oct 2019 05:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=from:subject:to:cc:references:openpgp:autocrypt:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=IGNKGWkmxcQYmW00srcnpM8ftzS6cg39mtga8uVr4vU=; b=jA5qExdMbri5SN/JHmmzm+/1IeDNTXIIswfNjlm7RSlRF+B3MDJ/WC8hhiCPQ7fM4B knUTI4YB+yEpGvkamF8oFfqCNZixUY5QPHIZ6Sr3K2rwwn6vrJdrajnXAyIhTAUydldp v+dIit0lgB6zTG731I5xdUXMz1Q/Q/a/3IW/gUiHBmrqY+la1H4W6Zk6WBUxNCQWqL5G 1mPq6/YAxcdVeAhsWAw9NA2ZqtDRpkNxkMZe1imAOTt6gm0JNSNcuW3jMmsqr3ZbR/qf Qaelzx4eeb96YPUtse+UdaucEEKQjoSuJzAZY94y+fmgoz/tOdqTmzPfbKF/RhMnUz9y bh8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding:content-language; bh=IGNKGWkmxcQYmW00srcnpM8ftzS6cg39mtga8uVr4vU=; b=PDypQw2iE217g6KPdOPSxX0zmfKVdP4aX6UsW1z3hDuqpPxxkPPYVzbf9sFaO3ylbt bY88EV50DwL9d3KnB1NxZzD7513g/AvWx097IDlvhxCSluvR+1kspQmvoaTAzUgKXWQE 2alh4kjqcsyaZ/1Q2xsjWxmSBcC32kgRMwSg2M4Ol9QrHEiF2/TfY94id++FsT5UXjuo OvmHXH88OFckTRulu40DgoNT4gHuocuKlu1/BJ1XmgjxNSzTfNbdHsLPjzITrZpg03JE iAnjeDK2+mTjfYfjW/5/4BeGcO/eu45SNebZKVDn9aFjFyPNBcBStHWg1p/7YAL2Tr8c Z8lA== X-Gm-Message-State: APjAAAX7zlbJveSqdQQJ8XAE3xGLI8H4/zKVDKm0G3/3p1OHglGiXbQr +sQlHjfK7AhqEVUkOn/Lc0PT X-Google-Smtp-Source: APXvYqzSFPo4Dwxq4SDsO1jc/3Hbg+4dZxSoNT726oL/AnGvAFwsyZU43c2MvVPMsV2sSuUqxRo9xw== X-Received: by 2002:a25:5f01:: with SMTP id t1mr11728239ybb.29.1571574700602; Sun, 20 Oct 2019 05:31:40 -0700 (PDT) Received: from [192.168.10.146] (99-10-92-30.lightspeed.rlghnc.sbcglobal.net. [99.10.92.30]) by smtp.gmail.com with ESMTPSA id m62sm2627636ywf.70.2019.10.20.05.31.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 20 Oct 2019 05:31:39 -0700 (PDT) From: Andrew Dunstan X-Google-Original-From: Andrew Dunstan Subject: Re: jsonb_set() strictness considered harmful to data To: Floris Van Nee , Ariadne Conill , Tomas Vondra Cc: "David G. Johnston" , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers References: <7dc242bd-b78f-2e0d-0c38-7b4b299f11bf@2ndQuadrant.com> <20191019161851.v7dwloiiav5yrpwu@development> <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> Openpgp: preference=signencrypt Autocrypt: addr=andrew.dunstan@2ndQuadrant.com; prefer-encrypt=mutual; keydata= xsBNBE7KWFkBCAClridxur2AIc7eW2AR7izbfp3EnNefie2HbLF0izW5Ik5UjX2HBXBx4syI gY6b0ugohXrr274+baoAlvSbq6cAoQuEVrk5IZFzt20b1Xkx65FwGSEj526yiKLocqkJceSq Xr9xcA5SGY+FZv441chh5SU92v4q6z+6LPpoHOh97ptAVXZYNTtU0LevyvD5lja0TzbvJm6C eFXitJfnm1pLEr0DGJCR/iUOl/N62Kh4855zZC7NHIjQHPOvV5Stz/l5ilDhvGVk+xkXFPys SjZoUr1rXhYLpiyi5sR0X9FHXT0KnGuz1F5ERO7ZTLSSQ6fJwPj6gOk9K+vvoKvoeql5ABEB AAHNL0FuZHJldyBEdW5zdGFuIDxhbmRyZXcuZHVuc3RhbkAybmRRdWFkcmFudC5jb20+wsCY BBMBAgBCAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAUJDyV6hBYhBOQ+WEYd/Hy/RGkV pZn6f8tZ/DuBBQJcH/EVAhkBAAoJEJn6f8tZ/DuB7BEH/iDWZEbVft2m2MT6SPjARzTupt/l xLLZ/Cl6n2US2hov5+fBbnR5xvECk/YCOfG9ICvKNlpFjceqNLRKStd8cmndnI+kDw91uNM2 hpL4aJMeW65XCHvqXlOLSwv5chBpXz9NG7FMaJ+q+59sWEWjcTNmjXgkEHn53y+1pc7nSLDe cr5ZI1aB3nGXRm1SoDY5PYZkUKMykW+YBZwgcs/Q5tRaE+siN7DKbz8E628+PerwAkmHPVXN MdJFD6gs4S0gDFA8IxcyIwZU2v4By+brzcJ9Se3FK5BYxBDHtaYZxgSrJAvOUOrLIZPQTQfL TtnVs3C3JTfrxCH1ceHtnA6dRuTOwE0ETspYWQEIANGc4zQULOxhbqO2dyD51YhqCNRmm9oK Waqf+wmW4tpDe/VVcxAnNizd4LWCHfzpb5cHAtGkOPePMfzWVf6nvdF7d3eglbtf59+zG7O7 llV0xSSoFiieQBsrGvqDInXYX/4mRRXMtyhM353/tixC9RWLs1oofyYmCPPXXY7h9R7en3B8 BoVrRFcdzlIY/NFNhFGW/9dkEiGjgna2Rk6e15kln4ZvFBWUg23p93w/pqXcxY6+k/8TEk+C 4R+M6w7o2PLGOjdZ+kPiUcw5H85zf/yZJwQXzisXaNduwWB6Vads9YC9dj6kPR1c4VGRqAaY L++LAEOqrlvm2TvqQqZRtnEAEQEAAcLAZQQYAQIADwIbDAUCXA6fpAUJDyV6xAAKCRCZ+n/L Wfw7geU4B/9vFFsVmWxerDWgNjyiK80zIPmlw/iwdUlU6FIu0JWLMg4093kvxBs7RMZV9hBq n3ekBvD4IvFsVLJrw9qzSI2FH3UeYy5WXpEs01Ppia60NOlvRDqXbryzuvfe+iYo6bVP3Ikr TPTNYL/BePUTD2DPvSI82SbGTyzuA7SJv6NRqqQDMIy1fU6KyQFLmQJp/QJyhKWzm9jWh8ee w8jVaoMY0Kbq5N7RqisEx1Lu/Iw646UphdYzQNymf+kbiU5Kf4I6DhzV8w9sie1Bo1juNj3I c5/fFJsmxljbnaDbXPcnFsur1Oo9mIHFakgWgOBMuxoWfjONiLjjLh/9+ZIqSSLX Message-ID: <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> Date: Sun, 20 Oct 2019 08:31:38 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <1571560798575.47024@Optiver.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Content-Language: en-MW List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 10/20/19 4:39 AM, Floris Van Nee wrote: > > FWIW I've been bitten by this 'feature' more than once as well, > accidentally erasing a column. Now I usually write js = jsonb_set(js, > coalesce(new_column, 'null'::jsonb)) to prevent erasing the whole > column, and instead setting the value to a jsonb null value, but I > also found the STRICT behavior very surprising at first.. > > > Understood. I think the real question here is what it should do instead when the value is NULL. Your behaviour above is one suggestion, which I personally find intuitive. Another has been to remove the associated key. Another is to return the original target. And yet another is to raise an exception, which is easy to write but really punts the issue back to the application programmer who will have to decide how to ensure they never pass in a NULL parameter. Possibly we could even add an extra parameter to specify what should be done. Also, the question will arise what to do when any of the other parameters are NULL. Should we return NULL in those cases as we do now? cheers andrew -- Andrew Dunstan https://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services