Re: Do blocks support transaction control?

From: hubert depesz lubaczewski <depesz(at)depesz(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Do blocks support transaction control?
Date: 2022-09-26 03:44:31
Message-ID: YzEgH26TCMdAsdPQ@depesz.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

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

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Bruce Momjian 2022-09-26 21:26:20 Re: DocBook 5.2
Previous Message PG Doc comments form 2022-09-24 18:27:48 PostgreSQL source distribution files