78

I created a function as shown below:

CREATE FUNCTION my_func(value INTEGER) RETURNS VOID AS $$
BEGIN
END;
$$ LANGUAGE plpgsql;

But I need to specify the parameter to drop the function as shown below:

DROP FUNCTION my_func(value INTEGER);

Because if not specifying the parameter as shown below:

DROP FUNCTION my_func;

Then, I got the error below:

ERROR: function name "my_func" is not unique
HINT: Specify the argument list to select the function unambiguously.

So, can I drop a function without parameters?

3 Answers 3

122

In Postgres functions can be overloaded, so parameters are necessary to distinguish overloaded functions. To unambiguously identify a function you can put only types of its parameters.

DROP FUNCTION my_func(INT);
Sign up to request clarification or add additional context in comments.

Comments

59

As of Postgres 10 you can drop functions by name only, as long as the names are unique to their schema.

Example:

drop function my_func;

Documentation here.

Comments

1

You need to specify zero or more parameters with () if there are multiple same name functions. *The doc explains Function Overloading.

For example, you create 2 functions as shown below:

CREATE FUNCTION my_func() RETURNS VOID AS $$
BEGIN
END;
$$ LANGUAGE plpgsql;
CREATE FUNCTION my_func(value INTEGER) RETURNS VOID AS $$
BEGIN
END;
$$ LANGUAGE plpgsql;

Then, you can drop the 1st function with the SQL below:

DROP FUNCTION my_func();

Or, you can drop the 2nd function with the SQL below:

DROP FUNCTION my_func(INTEGER);

And, you create 2 procedures as shown below:

CREATE PROCEDURE my_proc() LANGUAGE plpgsql AS $$
BEGIN
END;
$$;
CREATE PROCEDURE my_proc(value INTEGER) LANGUAGE plpgsql AS $$
BEGIN
END;
$$;

Then, you can drop the 1st procedure with the SQL below:

DROP PROCEDURE my_proc();

Or, you can drop the 2nd procedure with the SQL below:

DROP PROCEDURE my_proc(INTEGER);

Comments

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.