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 1oc6rm-0001E4-SY for pgsql-docs@arkaria.postgresql.org; Sat, 24 Sep 2022 15:14:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oc6rk-0002KA-Bz for pgsql-docs@arkaria.postgresql.org; Sat, 24 Sep 2022 15:14:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oc6rk-0002K0-0h for pgsql-docs@lists.postgresql.org; Sat, 24 Sep 2022 15:14:52 +0000 Received: from mail-ej1-x62e.google.com ([2a00:1450:4864:20::62e]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oc6re-0003qb-Ur for pgsql-docs@lists.postgresql.org; Sat, 24 Sep 2022 15:14:50 +0000 Received: by mail-ej1-x62e.google.com with SMTP id dv25so6022015ejb.12 for ; Sat, 24 Sep 2022 08:14:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date; bh=PTy04JufGk1v5AqsSnM3L6AcAupC2itc7FIw8N4Q1h0=; b=5nC2rknA+mjGAOIWKADdKAfy52hZjQ7X/ZY0GP0YT8dTeZb23xY6bZXn9lRM56Ml9S IdTqH4bpKYlLp203TCMpCQ+c73paTgntLxTiwuxyE2E5IuFUeKuHG7pxWHRbU6oKHh0k b7k6MqAjh9KPlDH+Kh07EtubrkWKr6ROon9kYDArcV/yFdKgcAhO8Qsd+VI2DYN6JJGF LmUb9qYr0qsu93SpAR+B0FlgGojGrgMPpvkDjoWeBezlcu8AWaMlsb8ikH0Fvp4LOIxt phohgcsfQ1i96fHRjRCSyk+0TQJx+mLhKys927wKSwJMIZVuvzO3nZizP1PywwOGefjV xrww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date; bh=PTy04JufGk1v5AqsSnM3L6AcAupC2itc7FIw8N4Q1h0=; b=m12ZEUTVaOo4L03P4YcNrxJ/BowLPExVBpEK38IW1UEFpmVUhp9oXiSEp5gf8/tsF+ Fys4xhTMrS9fTbO6xxv53mkzUDoFhikqGxI68mIGfrbeOR91cQyj1qURjzItJ5AXrXJp 5QRvAxO14oOO5pSh+s7oWETw3x97rz3dx5i7DMMxSNFI6Vv0Uwv9S75tiJQxCNVbpYz6 R6rp6eGK4AIxyJNICvIqjms5j3qXZWoqB1JIRFaSUEXM2nVU25+12xrGKkH0ZYgrrTrg 2f6hDqQQ7uG+0iezwYMdA2EHVJrOXfubfCOzAa6TNoiPCGWjOcGaMaY39VE0zet/vIKB i21Q== X-Gm-Message-State: ACrzQf3vMXUrzNW/boUlmb1hQLPRoePEwAnoD0rbPjsGwcF/Txr67/W7 /9xZY1kYzJjFHGfh6N0jTvc7yCJ4+qkmDA== X-Google-Smtp-Source: AMsMyM7dAxO46r308kS0qFRkrnsTKmqCCjj1JFeODKiGCcVCVEONtmfIQD2mJcJx7hoK2DXTeLtTKg== X-Received: by 2002:a17:907:7607:b0:770:7ec4:fb41 with SMTP id jx7-20020a170907760700b007707ec4fb41mr10853532ejc.685.1664032485381; Sat, 24 Sep 2022 08:14:45 -0700 (PDT) Received: from localhost.localdomain (62-47-150-179.adsl.highway.telekom.at. [62.47.150.179]) by smtp.gmail.com with ESMTPSA id ku2-20020a170907788200b007708635be05sm5670836ejc.4.2022.09.24.08.14.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Sep 2022 08:14:43 -0700 (PDT) Message-ID: Subject: Re: Do blocks support transaction control? From: Laurenz Albe To: depesz@depesz.com, pgsql-docs@lists.postgresql.org Date: Sat, 24 Sep 2022 17:14:42 +0200 In-Reply-To: <166394003436.654.15293085988078557076@wrigleys.postgresql.org> References: <166394003436.654.15293085988078557076@wrigleys.postgresql.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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. Yours, Laurenz Albe