pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
rollback previous commit if the current one fails
3+ messages / 2 participants
[nested] [flat]

* rollback previous commit if the current one fails
@ 2021-04-13 08:29  pinker <zaledwie10minut@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: pinker @ 2021-04-13 08:29 UTC (permalink / raw)
  To: pgsql-general

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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: rollback previous commit if the current one fails
@ 2021-04-13 10:48  luis.roberto@siscobra.com.br
  parent: pinker <zaledwie10minut@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: luis.roberto@siscobra.com.br @ 2021-04-13 10:48 UTC (permalink / raw)
  To: pinker <zaledwie10minut@gmail.com>; +Cc: pgsql-general

----- Mensagem original -----

> Any idea how to approach it?


Hi!

https://www.postgresql.org/docs/current/sql-savepoint.html



Luis R. Weck 





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: rollback previous commit if the current one fails
@ 2021-04-13 10:56  pinker <zaledwie10minut@gmail.com>
  parent: luis.roberto@siscobra.com.br
  0 siblings, 0 replies; 3+ messages in thread

From: pinker @ 2021-04-13 10:56 UTC (permalink / raw)
  To: pgsql-general

thank you Luis, but this is not supported in plpgsql



--
Sent from: https://www.postgresql-archive.org/PostgreSQL-general-f1843780.html





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2021-04-13 10:56 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13 08:29 rollback previous commit if the current one fails pinker <zaledwie10minut@gmail.com>
2021-04-13 10:48 ` luis.roberto@siscobra.com.br
2021-04-13 10:56   ` pinker <zaledwie10minut@gmail.com>

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