pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedSubstitute of TRY and CATCH in postgres
2+ messages / 2 participants
[nested] [flat]
* Substitute of TRY and CATCH in postgres
@ 2021-04-19 13:21 aditya desai <admad123@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: aditya desai @ 2021-04-19 13:21 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Substitute of TRY and CATCH in postgres
@ 2021-04-19 13:32 Thomas Kellerer <shammat@gmx.net>
parent: aditya desai <admad123@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Kellerer @ 2021-04-19 13:32 UTC (permalink / raw)
To: pgsql-sql@lists.postgresql.org
aditya desai schrieb am 19.04.2021 um 15:21:
> 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?
You need an exception block:
https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2021-04-19 13:32 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-04-19 13:21 Substitute of TRY and CATCH in postgres aditya desai <admad123@gmail.com>
2021-04-19 13:32 ` Thomas Kellerer <shammat@gmx.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox