pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: hubert depesz lubaczewski <depesz@depesz.com>
To: Laurenz Albe <laurenz.albe@cybertec.at>
Cc: pgsql-docs@lists.postgresql.org
Subject: Re: Do blocks support transaction control?
Date: Mon, 26 Sep 2022 05:44:31 +0200
Message-ID: <YzEgH26TCMdAsdPQ@depesz.com> (raw)
In-Reply-To: <b1b9330fed3738135aba8664a55a6fd8239985c8.camel@cybertec.at>
References: <166394003436.654.15293085988078557076@wrigleys.postgresql.org>
	<b1b9330fed3738135aba8664a55a6fd8239985c8.camel@cybertec.at>

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






view thread (3+ messages)

Message-ID: <YzEgH26TCMdAsdPQ@depesz.com>
Permalink:  ../YzEgH26TCMdAsdPQ@depesz.com/
Also on:    postgresql.org/message-id/YzEgH26TCMdAsdPQ@depesz.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: depesz@depesz.com, laurenz.albe@cybertec.at, pgsql-docs@lists.postgresql.org
  Subject: Re: Do blocks support transaction control?
  In-Reply-To: <YzEgH26TCMdAsdPQ@depesz.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox