> 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/server-programming/extend/xfunc-internal.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 36.9. 內部函式

### 36.9. 內部函式 [#](#xfunc-internal) <a href="#xfunc-internal" id="xfunc-internal"></a>

內部函式是以 C 撰寫並靜態連結至 PostgreSQL 伺服器的函式。函式定義的「主體」會指定函式的 C 語言名稱，無須與宣告供 SQL 使用的名稱相同。（為維持向後相容，空白主體表示 C 語言函式名稱與 SQL 名稱相同。）

通常伺服器中的所有內部函式都會在初始化資料庫叢集時宣告（請參閱[第 18.2 節](https://docs.postgresql.tw/19/server-administration/runtime/creating-cluster.md)），但使用者可用 `CREATE FUNCTION` 為內部函式建立額外別名。內部函式會在 `CREATE FUNCTION` 中以 `internal` 作為語言名稱宣告。舉例來說，若要為 `sqrt` 函式建立別名：

```

CREATE FUNCTION square_root(double precision) RETURNS double precision
    AS 'dsqrt'
    LANGUAGE internal
    STRICT;
```

（大多數內部函式預期宣告為「strict」。）

#### 注意

並非所有「預先定義」函式都是上述意義的「內部」函式；有些預先定義函式以 SQL 撰寫。

***

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


---

# 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/server-programming/extend/xfunc-internal.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.
