Re: write a sql block which will commit if both updates are successful else it will have to be rolled back - Mailing list pgsql-general

From David G. Johnston
Subject Re: write a sql block which will commit if both updates are successful else it will have to be rolled back
Date
Msg-id CAKFQuwZaPyVn4KzAO+aU16PWeCM6tFy9-A+wGim6So82Jg-krQ@mail.gmail.com
Whole thread Raw
In response to write a sql block which will commit if both updates are successful else it will have to be rolled back  (arun chirappurath <arunsnmimt@gmail.com>)
List pgsql-general
On Thursday, December 7, 2023, arun chirappurath <arunsnmimt@gmail.com> wrote:

Can someone guide me to "write a sql block which will commit if both updates are successful else it will have to be rolled back"?
would like to explicitly specify both commit and rollback in code..

 I would like to turn off the autocommit then execute the query.

As documented under DO if you make an explicit transaction then execute the DO it cannot have transaction control commands.  If you allow it to “auto-commit’’ then it can.  Though in that case writing either rollback or commit for such a simple linear procedure becomes pointless since a transaction will already commit or rollback appropriately depending on whether the procedure provokes an exception.

David J.

pgsql-general by date:

Previous
From: arun chirappurath
Date:
Subject: write a sql block which will commit if both updates are successful else it will have to be rolled back
Next
From: Noel Jones
Date:
Subject: Invalid Parent Index Issue Will Not Resolve Despite Multiple Attempts To Fix