I am brand new to Postgresql and am trying to write a function that calls another function, and then returns -1 if that function had any errors. I am coming from a T-SQL background and essentially want the equivalent of
CREATE PROCEDURE [dbo].[p_newproc]
AS
BEGIN
EXEC p_seed_table
IF @@ERROR <> 0
RETURN -1
...
END
So far I have found that I am likely going to use something like the following:
CREATE OR REPLACE FUNCTION public.fn_newfunc()
RETURNS void
AS
$$
BEGIN
PERFORM fn_seed_table();
EXCEPTION
WHEN
SQLSTATE <> '00000'
RAISE EXCEPTION '-1';
End;
$$
LANGUAGE 'plpgsql';
Any advice would be appreciated. Thanks.