Re: PostgreSQL transaction aborted on SQL error

Поиск
Список
Период
Сортировка
От Thomas Kellerer
Тема Re: PostgreSQL transaction aborted on SQL error
Дата
Msg-id 72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net
обсуждение исходный текст
Ответ на PostgreSQL transaction aborted on SQL error  (Urko Lekuona <urko@arima.eu>)
Список 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 по дате отправления:

Предыдущее
От: Andreas Joseph Krogh
Дата:
Сообщение: Sv: PostgreSQL transaction aborted on SQL error
Следующее
От: Srinivasa T N
Дата:
Сообщение: Re: Unexplained disk usage in AWS Aurora Postgres