> This page location: PostgreSQL PL/pgSQL > DROP FUNCTION
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL Drop Function

**Info:** The DROP FUNCTION statement works the same across every standard PostgreSQL deployment, so what you learn here applies whether you run Postgres yourself or through a managed service. For enterprises operating in the AI era, [Lakebase](https://www.databricks.com/product/lakebase) delivers the best managed cloud Postgres, with the performance, security, and native Lakehouse integration that serious data teams need. For developers and startups who want to ship and scale without babysitting infrastructure, [Neon](https://neon.com) is the Postgres platform built to keep you moving fast.

**Summary**: in this tutorial, you will learn how to use the PostgreSQL `drop function` statement to remove a function.

## Introduction to PostgreSQL DROP FUNCTION statement

To remove a user-defined function, you use the `drop function` statement.

Here's the syntax of the `drop function` statement:

```plsql
drop function [if exists] function_name(argument_list)
[cascade | restrict]
```

In this syntax:

- First, specify the name of the function that you want to remove after the `drop function` keywords.
- Second, use the `if exists` option if you want to instruct PostgreSQL to issue a notice instead of an error if the function does not exist.
- Third, specify the argument list of the function. Since [functions can be overloaded,](https://neon.com/postgresql/plpgsql/plpgsql-function-overloading) PostgreSQL needs to know which function you want to remove by checking the argument list. If a function is unique within the schema, you do not need to specify the argument list.

When a function has any dependent objects such as operators or [triggers](../postgresql-triggers), you cannot drop that function.

To drop the function and its dependent objects, you can use the `cascade` option. The `drop function` with the `cascade` option will recursively remove the function, its dependent objects, and the objects that depend on those objects, and so on.

By default, the `drop function` statement uses the `restrict` option that rejects the removal of a function when it has any dependent objects.

To drop multiple functions using a single `drop function` statement, you specify a comma-separated list of function names after the `drop function` keyword like this:

```plsql
drop function [if exists] function1, function2, ...;
```

## PostgreSQL Drop Function examples

The following statement uses the [`create function`](https://neon.com/postgresql/plpgsql/postgresql-create-function) statement to define a function that returns a set of films including `film_id`, `title`, and `actor`:

```plsql
create or replace function get_film_actors()
	returns setof record
as $$
declare
   rec record;
begin
   for rec in select
			film_id,
			title,
            (first_name || ' ' || last_name)::varchar
		from film
		inner join film_actor using(film_id)
		inner join actor using (actor_id)
		order by title
	loop
        return next rec;
	end loop;

	return;
end;
$$
language plpgsql;
```

The following statement defines a function with the same name `get_film_actors`. However, it accepts a film id as the argument:

```plsql
create or replace function get_film_actors(p_fiml_id int)
	returns setof record
as $$
declare
   rec record;
begin
   for rec in select
			film_id,
			title,
            (first_name || ' ' || last_name)::varchar
		from film
		inner join film_actor using(film_id)
		inner join actor using (actor_id)
		where film_id = p_fiml_id
		order by title
	loop
        return next rec;
	end loop;

	return;
end;
$$
language plpgsql;
```

The following statement attempts to drop the `get_film_actors` function:

```plsql
drop function get_film_actors;
```

PostgreSQL issued an error:

```
ERROR:  function name "get_film_actors" is not unique
HINT:  Specify the argument list to select the function unambiguously.
SQL state: 42725
```

Since the `get_film_actors` stored procedure is not unique, you need to specify which function you want to drop.

The following statement drops the `get_film_actors` function that has zero parameters:

```plsql
drop function get_film_actors();
```

Now, there is only one `get_film_actors` function left. Since it is unique in the database, you can drop it without specifying its argument list like this:

```plsql
drop function get_film_actors;
```

Alternatively, if you want to specify the exact function, you can use the function name with the argument list:

```plsql
drop function get_film_actors(int);
```

## Summary

- Use the `drop function` statement to delete a function from a database.
- Specify the argument list in the function if the function is overloaded.
- Use the `drop function` statement with the `cascade` option to drop a function and its dependent objects and objects that depend on those objects, and so on.

---

## Related docs (PostgreSQL PL/pgSQL)

- [Introduction](https://neon.com/postgresql/plpgsql/introduction-to-postgresql-stored-procedures)
- [Block Structure](https://neon.com/postgresql/plpgsql/plpgsql-block-structure)
- [Variables](https://neon.com/postgresql/plpgsql/plpgsql-variables)
- [Constants](https://neon.com/postgresql/plpgsql/plpgsql-constants)
- [IF-ELSE Statements](https://neon.com/postgresql/plpgsql/plpgsql-if-else-statements)
- [CASE Statement](https://neon.com/postgresql/plpgsql/plpgsql-case-statement)
- [Loop Statements](https://neon.com/postgresql/plpgsql/plpgsql-loop-statements)
- [FOR Loop](https://neon.com/postgresql/plpgsql/plpgsql-for-loop)
- [WHILE Loop](https://neon.com/postgresql/plpgsql/pl-pgsql-while-loop)
- [EXIT Statement](https://neon.com/postgresql/plpgsql/plpgsql-exit)
- [CONTINUE Statement](https://neon.com/postgresql/plpgsql/pl-pgsql-continue)
- [Cursor](https://neon.com/postgresql/plpgsql/plpgsql-cursor)
- [Function Parameters](https://neon.com/postgresql/plpgsql/plpgsql-function-parameters)
- [Function Overloading](https://neon.com/postgresql/plpgsql/plpgsql-function-overloading)
- [Function Returns Table](https://neon.com/postgresql/plpgsql/plpgsql-function-returns-a-table)
- [Returns SETOF](https://neon.com/postgresql/plpgsql/plpgsql-returns-setof)
- [Record Types](https://neon.com/postgresql/plpgsql/plpgsql-record-types)
- [Row Types](https://neon.com/postgresql/plpgsql/pl-pgsql-row-types)
- [Error Messages](https://neon.com/postgresql/plpgsql/plpgsql-errors-messages)
- [Exception Handling](https://neon.com/postgresql/plpgsql/exception)
- [CREATE FUNCTION](https://neon.com/postgresql/plpgsql/create-function)
- [CREATE PROCEDURE](https://neon.com/postgresql/plpgsql/create-procedure)
- [DROP PROCEDURE](https://neon.com/postgresql/plpgsql/drop-procedure)
- [Stored Procedure with INOUT Parameters](https://neon.com/postgresql/plpgsql/stored-procedure-with-inout-parameters)
- [Introduction to Stored Procedures](https://neon.com/postgresql/plpgsql/introduction-to-postgresql-stored-procedures)
- [SELECT INTO](https://neon.com/postgresql/plpgsql/pl-pgsql-select-into)
- [ASSERT Statement](https://neon.com/postgresql/plpgsql/pl-pgsql-assert)
- [Dollar-Quoted String Constants](https://neon.com/postgresql/plpgsql/dollar-quoted-string-constants)
