Subject: Re: Big script execution

From: Laurenz Albe <[email-masked]>
Date: Mon, 10 Mar 2025 17:31:51 +0100

On Mon, 2025-03-10 at 16:42 -0500, Igor Korot wrote:
> I am trying to execute a huge script (~40K lines) that will populate
> my database.
> 
> The script starts with "BEGIN TRANSACTION" and will end
> with "COMMIT".
> 
> however I'd like to rollback if there is an error encounter.
> 
> When I execute it from the Terminal I do use
> 
> -v ON_ERROR_STOP=1
> 
> but I'd like to rolback the transaction so it starts a fresh every time.
> 
> Is there some kind of
> 
> ON ERROR ROLLBACK
> 
> command I can put inside the script?

That happens automatically: if you are running the whole script in a
single transaction, any error will make the whole transaction roll back.

Yours,
Laurenz Albe

---

From: Igor Korot <[email-masked]>
Date: Mon, 10 Mar 2025 11:35:45 -0500

Hi, Laurenz,

> single transaction, any error will make the whole transaction roll back.

Will the tables also be deleted?
The CREATE TABLE statements are part of this big transaction.

Thank you.

---

From: Christophe Pettus <[email-masked]>
Date: Mon, 10 Mar 2025 09:36:51 -0700

> On Mar 10, 2025, at 09:35, Igor Korot <[email-masked]> wrote:
> 

Yes.  DDL is transactional in PostgreSQL just like DML.

---

From: Igor Korot <[email-masked]>
Date: Mon, 10 Mar 2025 11:48:24 -0500

Thank you!

---

From: Igor Korot <[email-masked]>
Date: Mon, 10 Mar 2025 16:42:24 -0500

Hi, ALL,

-v ON_ERROR_STOP=1

Is there some kind of

ON ERROR ROLLBACK

Thank you.