Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocf2v-0005FE-OV for pgsql-docs@arkaria.postgresql.org; Mon, 26 Sep 2022 03:44:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ocf2u-0002LW-KE for pgsql-docs@arkaria.postgresql.org; Mon, 26 Sep 2022 03:44:40 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocf2u-0002LM-Bi for pgsql-docs@lists.postgresql.org; Mon, 26 Sep 2022 03:44:40 +0000 Received: from lana.depesz.com ([88.198.49.178] helo=depesz.com) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ocf2n-0002N9-EQ for pgsql-docs@lists.postgresql.org; Mon, 26 Sep 2022 03:44:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=depesz.com; s=20170201; h=In-Reply-To:Content-Type:MIME-Version:References:Reply-To: Message-ID:Subject:Cc:To:Sender:From:Date:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=fVinS0wgOR7Yov0HgCDYGn31ftRAyqIdWzlcn/vdsFk=; b=e9AwkT2fr/uIT5G1yT4z7wVpSy dWxS7+MG6fGnL2s50gFN63fn9QN2t8WPK0GzoQEc1EIUANUVl9juZ4wTSqIBrh9J9OW9TdYwEKQQG OwbcoRjHEACavSjx+RPE3Gi4fm9/zaMBUjQs4H+qt/w2d97GyJka0nT67fQsQxwgn+pQ=; Received: from depesz by depesz.com with local (Exim 4.94.2) (envelope-from ) id 1ocf2l-0084m1-3Q; Mon, 26 Sep 2022 05:44:31 +0200 Date: Mon, 26 Sep 2022 05:44:31 +0200 From: hubert depesz lubaczewski Sender: depesz@depesz.com To: Laurenz Albe Cc: pgsql-docs@lists.postgresql.org Subject: Re: Do blocks support transaction control? Message-ID: Reply-To: depesz@depesz.com References: <166394003436.654.15293085988078557076@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sat, Sep 24, 2022 at 05:14:42PM +0200, Laurenz Albe wrote: > On Fri, 2022-09-23 at 13:33 +0000, PG Doc comments form wrote: > > Page: https://www.postgresql.org/docs/14/sql-do.html > > Description: > > > > Apparently now DO blocks support COMMIT; - which make them more like > > procedures than functions. > > > > Tried it with: > > > > create table z (a int4, b int4); > > insert into z (a,b) select i, i from generate_Series(1,10) i; > > do $$ > > declare > > begin > > update z set b = 2; > > commit; > > perform pg_sleep(120); > > end; > > $$ language plpgsql; > > > > And while it was running, in another psql sessions, I: > > > > 1. could see b= 2 > > 2. could update any of the rows in z. > > > > Is it documented anywhere? DO docs say that do is like function, which it > > doesn't seem to be? > > The documentation says: > > If DO is executed in a transaction block, then the procedure code cannot execute > transaction control statements. Transaction control statements are only allowed > if DO is executed in its own transaction. > > That sentence would not make sense if COMMIT were not allowed in a DO statement. > So it is not spelled out, but implicitly clear. Sorry, missed that, focused too much on the earlier part. Thanks a lot. Best regards, depesz