0

I have 2 functions in Postgresql 9.3:

CREATE OR REPLACE FUNCTION Function_A(param_id integer, param_name text)
  RETURNS void AS
$BODY$
DECLARE

my_id integer;
my_name text;

BEGIN

    my_id = somefunction(param_id);
    my_name = somefunction(param_name);
    insert into tableA(id, name) values (my_id, my_name);

END

  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION Function_A(integer, text)
  OWNER TO postgres;

CREATE OR REPLACE FUNCTION Function_B(param_id bigint, param_name text)
  RETURNS void AS
$BODY$
DECLARE

BEGIN

    insert into tableC(id, name) values (param_id, param_name);

        perform Function_A(param_id, param_name);


END
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;
ALTER FUNCTION Function_B(bigint, text)
  OWNER TO postgres;

So, I have problem, when Function A returns error, Function B does not insert data into table C.

I want something like this:

If Perform Function A returns error resume next, so my Function B can insert data into table C and continue without problem.

Is this possible?

2
  • How are the 2 functions being called? Are both the calls part of same transaction? Commented Mar 11, 2019 at 14:29
  • Yes, it is the same transaction. And I want to continue with transaction even if the Function A returns error. Commented Mar 11, 2019 at 14:53

1 Answer 1

1

Without the actual SQL code, we cannot actually help you that much. If you want to force a function to continue without caring about errors, then you can use SQL exception syntax

EXCEPTION WHEN OTHERS THEN
    -- keep looping
END;
Sign up to request clarification or add additional context in comments.

1 Comment

I edited my post, but I am new here and don't know how to format these functions to look nice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.