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 1iMdhR-00038K-UX for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Oct 2019 19:50:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iMdhQ-0004Oo-2q for pgsql-hackers@arkaria.postgresql.org; Mon, 21 Oct 2019 19:50:40 +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 1iMdhP-0004Oa-Lk for pgsql-hackers@lists.postgresql.org; Mon, 21 Oct 2019 19:50:39 +0000 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iMdhM-0004JO-3s for pgsql-hackers@lists.postgresql.org; Mon, 21 Oct 2019 19:50:39 +0000 Received: by mail-wr1-x441.google.com with SMTP id s1so6601826wro.0 for ; Mon, 21 Oct 2019 12:50:35 -0700 (PDT) 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:user-agent; bh=KEyijuDFtfX9O7jnMG1ICzNq/uDq13KNbLmCmQGi1CQ=; b=PxkUF9b7dVhaaeZIFqNSKRFaUlujsb1OqqE1Qf93kudZQDXs5GdujTqu5zWkwI1AQv b+ZbCcCENNjaZJXsPbt5jjSoNqMsbERkVY9B/QeDawp1AuNseq5I/+enwVIsrrAArugg wqtrjC0NZnkWivolkJuqwz6rq8+/zNWoATImwVqNVy03e2I71wG53VZfB2tz2nkewfXQ +ZilJ46+K6cXMz8yAwRd5xBuTGFRF/IdZqKM3iDRvZ1mOQOFLF2gsbwhj9bBa9rvmi4h jnWkx4CcsaQS6lQC2F9gMxzIVXAoKSg/QwNdvhYm0vQ5sikA2gZXked3v2rmB9QwAu2L xWmA== 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:user-agent; bh=KEyijuDFtfX9O7jnMG1ICzNq/uDq13KNbLmCmQGi1CQ=; b=QG1zprpFG3GTbVgLcwZ2JjfcrlI38LWySYb7QFGt9gDaJHY8xEJ7YbaFF4qSk4Qbbc PnpYlzorZq8XfZDvHiqog6oWw4qwSjC5OZWPimtBM8dcIUXAY66mNAhkeeNuMNWbiYOW j7etpRoCC0qPCCHj/natSIG8toLx2OtsleSNX+k+iNsDVtzuz69g+DbUYD08mQNhs16h 7ZxfO4aoVZceaiK/9IN0xuAx6zk0hdGf/HCP4pikBVQ7EKgGZ8sMTCb18Achj9EUPrWP M4VLT/NqO8nXH6kYlQJ1I01CRJsj1TWt3oUG0ibLjp+B9Rwqa/PYLHNSjzrgxYn5MeBB 2dsw== X-Gm-Message-State: APjAAAWPOf2CgvMXkGpHqmgSLm7Hf94NOwlBbklkjsfoU8qGBbBl8G1o KwXfWmlBnAmIrNkRiaFic/NV1g== X-Google-Smtp-Source: APXvYqzS7uHTIB9c840mLXpl7UZdZPUuFGfz5P6o6FkEsEDXJLo657pBgJp4MpkfpZblemSxv+T2kA== X-Received: by 2002:a5d:4945:: with SMTP id r5mr3845wrs.37.1571687434179; Mon, 21 Oct 2019 12:50:34 -0700 (PDT) Received: from localhost (ip-86-49-253-183.net.upcbroadband.cz. [86.49.253.183]) by smtp.gmail.com with ESMTPSA id 126sm16767223wma.48.2019.10.21.12.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Oct 2019 12:50:33 -0700 (PDT) Date: Mon, 21 Oct 2019 21:50:31 +0200 From: Tomas Vondra To: Adrian Klaver Cc: Andrew Dunstan , "David G. Johnston" , Floris Van Nee , Ariadne Conill , Mark Felder , "pgsql-generallists.postgresql.org" , PostgreSQL Hackers Subject: Re: jsonb_set() strictness considered harmful to data Message-ID: <20191021195031.v4hzx5ytkjjsbfbv@development> References: <20191019192723.luarxhq57qkzuncw@development> <1571560798575.47024@Optiver.com> <34a7ff88-0d86-0990-4eac-48159df8d7f2@2ndQuadrant.com> <5db07acf-bc75-edf8-60af-905c0adadb68@2ndQuadrant.com> <20191020201839.olpuyuzixagcvvud@development> <5b8a26bf-6b46-71f3-a99e-3fb9a8095232@2ndQuadrant.com> <20191021060701.or6a6a7lg3asixom@development> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Mon, Oct 21, 2019 at 08:06:46AM -0700, Adrian Klaver wrote: >On 10/20/19 11:07 PM, Tomas Vondra wrote: >>On Sun, Oct 20, 2019 at 06:51:05PM -0400, Andrew Dunstan wrote: > >> >>True. And AFAIK catching exceptions is not really possible in some code, >>e.g. in stored procedures (because we can't do subtransactions, so no >>exception blocks). >> > >Can you explain the above to me as I thought there are exception >blocks in stored functions and now sub-transactions in stored >procedures. > Sorry for the confusion - I've not been particularly careful when writing that response. Let me illustrate the issue with this example: CREATE TABLE t (a int); CREATE OR REPLACE PROCEDURE test() LANGUAGE plpgsql AS $$ DECLARE msg TEXT; BEGIN -- SAVEPOINT s1; INSERT INTO t VALUES (1); -- COMMIT; EXCEPTION WHEN others THEN msg := SUBSTR(SQLERRM, 1, 100); RAISE NOTICE 'error: %', msg; END; $$; CALL test(); If you uncomment the SAVEPOINT, you get NOTICE: error: unsupported transaction command in PL/pgSQL because savepoints are not allowed in stored procedures. Fine. If you uncomment the COMMIT, you get NOTICE: error: cannot commit while a subtransaction is active which happens because the EXCEPTION block creates a subtransaction, and we can't commit when it's active. But we can commit outside the exception block: CREATE OR REPLACE PROCEDURE test() LANGUAGE plpgsql AS $$ DECLARE msg TEXT; BEGIN BEGIN INSERT INTO t VALUES (1); EXCEPTION WHEN others THEN msg := SUBSTR(SQLERRM, 1, 100); RAISE NOTICE 'error: %', msg; END; COMMIT; END; $$; regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services