From: Thomas Kellerer <shammat@gmx.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: PostgreSQL transaction aborted on SQL error
Date: Tue, 4 Aug 2020 11:28:13 +0200
Message-ID: <72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net> (raw)
In-Reply-To: <CAKjfNx+Ztikjp8Wmy+t5KHLudtWuF0ApWVjmFObhyBuS=BZdwA@mail.gmail.com>
References: <CAKjfNx+Ztikjp8Wmy+t5KHLudtWuF0ApWVjmFObhyBuS=BZdwA@mail.gmail.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: shammat@gmx.net
Subject: Re: PostgreSQL transaction aborted on SQL error
In-Reply-To: <72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net>
References: <CAKjfNx+Ztikjp8Wmy+t5KHLudtWuF0ApWVjmFObhyBuS=BZdwA@mail.gmail.com> <72725856-943d-2ad0-905f-aad2ea242f2f@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox