Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL plpgsql try catch block equivalent

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?

like image 607
Daniel L. VanDenBosch Avatar asked Aug 17 '18 18:08

Daniel L. VanDenBosch


1 Answers

Callbacks can handle potential errors:

https://www.postgresql.org/docs/9.4/static/ecpg-errors.html

like image 181
n8. Avatar answered Sep 26 '22 21:09

n8.