Re: PostgreSQL transaction aborted on SQL error

From: Thomas Kellerer <shammat(at)gmx(dot)net>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: PostgreSQL transaction aborted on SQL error
Date: 2020-08-04 09:28:13
Message-ID: 72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Srinivasa T N 2020-08-04 09:39:26 Re: Unexplained disk usage in AWS Aurora Postgres
Previous Message Andreas Joseph Krogh 2020-08-04 09:25:06 Sv: PostgreSQL transaction aborted on SQL error