From: pinker <zaledwie10minut@gmail.com>
To: pgsql-general@postgresql.org
Subject: rollback previous commit if the current one fails
Date: Tue, 13 Apr 2021 01:29:22 -0700 (MST)
Message-ID: <1618302562353-0.post@n3.nabble.com> (raw)
Hi,
i need to emulate oracle's savepoint behaviour inside of the plpgsql
function.
This function is able to insert all the rows that weren't caught on the
exception, but i need also to rollback the insert that happens before the
exception.
So let's say the exception is thrown when j=3 so i need also to rollback
j=2.
Any idea how to approach it?
DROP TABLE IF EXISTS test;
CREATE TABLE test
(
id INT
);
CREATE OR REPLACE PROCEDURE test()
AS
$$
DECLARE
j INT;
BEGIN
FOR j IN 0..6
LOOP
BEGIN
INSERT INTO test VALUES (1 / j);
EXCEPTION
WHEN OTHERS THEN
END;
END LOOP;
END;
$$ LANGUAGE plpgsql;
CALL test();
TABLE test;
--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html
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: zaledwie10minut@gmail.com
Subject: Re: rollback previous commit if the current one fails
In-Reply-To: <1618302562353-0.post@n3.nabble.com>
References: <1618302562353-0.post@n3.nabble.com>
* 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