Substitute of TRY and CATCH in postgres - Mailing list pgsql-sql

From aditya desai
Subject Substitute of TRY and CATCH in postgres
Date
Msg-id CAN0SRDGms=dHCsgrdHdya6ygFRNRsBj6of1=O3+wSVbSt-u2uA@mail.gmail.com
Whole thread Raw
Responses Re: Substitute of TRY and CATCH in postgres  (Thomas Kellerer <shammat@gmx.net>)
List pgsql-sql
Hi ,
We have a MSSQL proc which reads as below. We have to convert it to Postgres using TRY CATCH. I googled about it and could not find significant information. Can someone help?

SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 
 
 
 
 CREATE PROCEDURE [SaveEmployeeOverview]
 (
  p_employeeNumber int,
        p_dept char;
        p_subdept;
  )
 AS
 BEGIN   
 BEGIN TRY
 
 
 
 IF EXISTS(
  SELECT TOP 1 1 FROM employee WHERE employeenumber=p_employeenumber
 )
                
 BEGIN
  UPDATE employee 
  SET      dept=p_dept 
           subdept=p_subdept
  WHERE employeenumber=@employeenumner  
 
 END
 
 ELSE 
 
 BEGIN
               
 
  INSERT INTO [dbo].[employee] (employeenumber , dept,subdept) values(@p_employeenumber,@p_dept,@p_subdept)
     

 
 END
                                 
 SELECT  Result                                   =             1,
                                 ErrorDesc                            =             ''
                                 
 RETURN 0
                 
 END TRY
 BEGIN CATCH
 
 SELECT  Result                                   =             -1,
                                 ErrorDesc                            =             ERROR_MESSAGE()
 END CATCH
 END
 
 
 
 
 
 GO
 
Regards,
Aditya.

pgsql-sql by date:

Previous
From: MichaelDBA
Date:
Subject: Re: URL Decode function
Next
From: Thomas Kellerer
Date:
Subject: Re: Substitute of TRY and CATCH in postgres