Re: PostgreSQL transaction aborted on SQL error - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: PostgreSQL transaction aborted on SQL error
Date
Msg-id 72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net
Whole thread Raw
In response to PostgreSQL transaction aborted on SQL error  (Urko Lekuona <urko@arima.eu>)
List pgsql-general
Urko Lekuona schrieb am 04.08.2020 um 10:44:
> First time writing here, I hope this is the right place to ask this
> kind of question. I've been working with PostgreSQL for a while now
> but i've just found out that PostgreSQL marks my transaction for
> ROLLBACK and even stops the execution of the transaction if an error
> occurs.

Which is exactly how a transaction is defined:

Either all statements are successful or none.


> If you run it, you'd see that when the unique key constraint is
> violated, my transaction is stopped

You can use INSERT ON CONFLICT DOT NOTHING to avoid that.


> make it work like other RDBMS do, where if a statement failed, the
> transaction could continue

Which completely violates the idea of a transaction.

The choices you have are:

* use auto-commit
* make sure your inserts don't throw an error
* use manual savepoints around each statement (don't forget DDL statements!)

Thomas



pgsql-general by date:

Previous
From: Andreas Joseph Krogh
Date:
Subject: Sv: PostgreSQL transaction aborted on SQL error
Next
From: Srinivasa T N
Date:
Subject: Re: Unexplained disk usage in AWS Aurora Postgres