8
votes

I am using PostgreSQL 9.6.

I have a PROCEDURE in sql server. That makes use of a try catch block. It looks a little bit like the code below:

        BEGIN TRANSACTION
        BEGIN TRY
        --do stuff here
        COMMIT TRANSACTION
        END TRY
        BEGIN CATCH
        ROLLBACK TRANSACTION
        --do error stuff here
        END CATCH

Upon doing some research, It seems like postgres does not make use of try catch. Is there some way to handle this in postgres the same way sql server does?

1
It is BEGIN ... EXCEPTION ... END in PL/pgSQL. But you cannot commit in a function. - Laurenz Albe
so all functions autocommit? - Daniel L. VanDenBosch
No; every function runs inside a single transaction (of course several functions can run in te same transaction, but you cannot commit or rollback inside a function). PostgreSQL v11 changes that. - Laurenz Albe

1 Answers

1
votes