Substitute of TRY and CATCH in postgres

From: aditya desai <admad123(at)gmail(dot)com>
To: pgsql-sql(at)lists(dot)postgresql(dot)org
Subject: Substitute of TRY and CATCH in postgres
Date: 2021-04-19 13:21:53
Message-ID: CAN0SRDGms=dHCsgrdHdya6ygFRNRsBj6of1=O3+wSVbSt-u2uA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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=(at)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.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2021-04-19 13:32:41 Re: Substitute of TRY and CATCH in postgres
Previous Message MichaelDBA 2021-04-06 13:07:03 Re: URL Decode function