public inbox for [email protected]  
help / color / mirror / Atom feed
Re: Big script execution
5+ messages / 3 participants
[nested] [flat]

* Re: Big script execution
@ 2025-03-10 16:31  Laurenz Albe <[email protected]>
  parent: Igor Korot <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Laurenz Albe @ 2025-03-10 16:31 UTC (permalink / raw)
  To: Igor Korot <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>

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






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Big script execution
@ 2025-03-10 16:35  Igor Korot <[email protected]>
  parent: Laurenz Albe <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Igor Korot @ 2025-03-10 16:35 UTC (permalink / raw)
  To: Laurenz Albe <[email protected]>; +Cc: pgsql-generallists.postgresql.org <[email protected]>

Hi, Laurenz,

On Mon, Mar 10, 2025, 11:31 AM Laurenz Albe <[email protected]>
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.


> Yours,
> Laurenz Albe
>


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Big script execution
@ 2025-03-10 16:36  Christophe Pettus <[email protected]>
  parent: Igor Korot <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Christophe Pettus @ 2025-03-10 16:36 UTC (permalink / raw)
  To: Igor Korot <[email protected]>; +Cc: Laurenz Albe <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>



> On Mar 10, 2025, at 09:35, Igor Korot <[email protected]> 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.






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Big script execution
@ 2025-03-10 16:48  Igor Korot <[email protected]>
  parent: Christophe Pettus <[email protected]>
  0 siblings, 0 replies; 5+ messages in thread

From: Igor Korot @ 2025-03-10 16:48 UTC (permalink / raw)
  To: Christophe Pettus <[email protected]>; +Cc: Laurenz Albe <[email protected]>; pgsql-generallists.postgresql.org <[email protected]>

Thank you!

On Mon, Mar 10, 2025, 11:37 AM Christophe Pettus <[email protected]> wrote:

>
>
> > On Mar 10, 2025, at 09:35, Igor Korot <[email protected]> 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.
>


^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Big script execution
@ 2025-03-10 21:42  Igor Korot <[email protected]>
  0 siblings, 1 reply; 5+ messages in thread

From: Igor Korot @ 2025-03-10 21:42 UTC (permalink / raw)
  To: pgsql-generallists.postgresql.org <[email protected]>

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.






^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2025-03-10 21:42 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-03-10 21:42 Big script execution Igor Korot <[email protected]>
2025-03-10 16:31 ` Laurenz Albe <[email protected]>
2025-03-10 16:35   ` Igor Korot <[email protected]>
2025-03-10 16:36     ` Christophe Pettus <[email protected]>
2025-03-10 16:48       ` Igor Korot <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox