I need to re-create a group of functions but I don't want to check their parameters to use drop if there are functions with the same names but different parameters. Is this possible to drop/recreate them only by name?
Or is this possible to catch exceptions, raise errors and continue to execute the transaction?
I'm trying to do it using
DO $$
BEGIN
BEGIN
CREATE OR REPLACE FUNCTION public.test(id integer)
RETURNS text[]
LANGUAGE plpgsql
AS $function$
begin
end;
$function$
;
EXCEPTION
WHEN duplicate_function THEN RAISE NOTICE 'already exists';
END;
END;
$$;
But It completes scripts quietly and does not raise any errors.
CREATE OR REPLACEwill do what it says, replace it, when it's already there, so why would you expect an exception "duplicate_function" would be thrown?CREATE OR REPLACEwill create the function with same name but a different signature, in other words it willoverloadthe function. See CREATE FUNCTION for more info. An error will be thrown if you change thereturntype though.CREATE OR REPLACEtoCREATEwhy it still not raising my error message? I'm getting [42723] error, as I understand this is a duplicate_function error