> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/reference/sql-commands/sql-dropfunction.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# DROP FUNCTION

### DROP FUNCTION

DROP FUNCTION — 移除函式

### 語法

```

DROP FUNCTION [ IF EXISTS ] name [ ( [ [ argmode ] [ argname ] argtype [, ...] ] ) ] [, ...]
    [ CASCADE | RESTRICT ]
```

### 說明

`DROP FUNCTION` 會移除現有函式的定義。要執行此命令，使用者必須是該函式的擁有者。必須指定函式的引數型別，因為可能存在多個名稱相同但引數列表不同的函式。

### 參數

`IF EXISTS` : 函式不存在時不擲出錯誤；此情況會發出 notice。

*`name`* : 現有函式的名稱（可選擇以綱要限定）。若未指定引數列表，該名稱在其綱要中必須是唯一的。

*`argmode`* : 引數的模式：`IN`、`OUT`、 `INOUT` 或 `VARIADIC`。 若省略，預設為 `IN`。 請注意，`DROP FUNCTION` 實際上並不理會 `OUT` 引數，因為只需要輸入引數就能判定函式的身分。 因此只需列出 `IN`、`INOUT` 與 `VARIADIC` 引數就足夠了。

*`argname`* : 引數的名稱。 請注意，`DROP FUNCTION` 實際上並不理會引數名稱，因為只需要引數的資料型別就能判定函式的身分。

*`argtype`* : 函式引數（若有）的資料型別（可選擇以綱要限定）。

`CASCADE` : 自動移除相依於函式的物件（例如運算子或觸發程序），以及相依於這些物件的所有物件 （請參閱[第 5.15 節](https://docs.postgresql.tw/19/the-sql-language/ddl/ddl-depend.md)）。

`RESTRICT` : 若有任何物件相依於函式則拒絕移除。這是預設行為。

### 範例

以下命令會移除平方根函式：

```

DROP FUNCTION sqrt(integer);
```

在一個命令中移除多個函式：

```

DROP FUNCTION sqrt(integer), sqrt(bigint);
```

若函式名稱在其綱要中是唯一的，就可以不加引數列表來引用它：

```

DROP FUNCTION update_employee_salaries;
```

請注意，這與以下命令不同：

```

DROP FUNCTION update_employee_salaries();
```

後者引用的是沒有引數的函式；而前一種寫法只要名稱是唯一的，就可以引用具有任意數量引數（包括零個）的函式。

### 相容性

此命令符合 SQL 標準，但有以下 PostgreSQL 擴充功能：

* 標準只允許每個命令移除一個函式。
* `IF EXISTS` 選項
* 指定引數模式與名稱的能力

### 另請參閱

[CREATE FUNCTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-createfunction.md), [ALTER FUNCTION](https://docs.postgresql.tw/19/reference/sql-commands/sql-alterfunction.md), [DROP PROCEDURE](https://docs.postgresql.tw/19/reference/sql-commands/sql-dropprocedure.md), [DROP ROUTINE](https://docs.postgresql.tw/19/reference/sql-commands/sql-droproutine.md)

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/sql-dropfunction.html)（原文版本：18.6；核對日期：2026-10-03）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/reference/sql-commands/sql-dropfunction.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
