Big script execution

Started by Igor Korotabout 1 year ago5 messagesgeneral
Jump to latest
#1Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Igor Korot (#5)
Re: Big script execution

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

#2Igor Korot
ikorot01@gmail.com
In reply to: Laurenz Albe (#1)
Re: Big script execution

Hi, Laurenz,

On Mon, Mar 10, 2025, 11:31 AM Laurenz Albe <laurenz.albe@cybertec.at>
wrote:

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.

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

Thank you.

Show quoted text

Yours,
Laurenz Albe

#3Christophe Pettus
xof@thebuild.com
In reply to: Igor Korot (#2)
Re: Big script execution

On Mar 10, 2025, at 09:35, Igor Korot <ikorot01@gmail.com> wrote:

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

Yes. DDL is transactional in PostgreSQL just like DML.

#4Igor Korot
ikorot01@gmail.com
In reply to: Christophe Pettus (#3)
Re: Big script execution

Thank you!

On Mon, Mar 10, 2025, 11:37 AM Christophe Pettus <xof@thebuild.com> wrote:

Show quoted text

On Mar 10, 2025, at 09:35, Igor Korot <ikorot01@gmail.com> wrote:

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

Yes. DDL is transactional in PostgreSQL just like DML.

#5Igor Korot
ikorot01@gmail.com

Hi, ALL,
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?

Thank you.