Substitute of TRY and CATCH in postgres
От | aditya desai |
---|---|
Тема | Substitute of TRY and CATCH in postgres |
Дата | |
Msg-id | CAN0SRDGms=dHCsgrdHdya6ygFRNRsBj6of1=O3+wSVbSt-u2uA@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Substitute of TRY and CATCH in postgres
|
Список | 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 по дате отправления: