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

# 第 40 章 程序語言

### 第 40 章 程序語言

**目錄**

[40.1. 安裝程序語言](https://docs.postgresql.tw/19/server-programming/xplang/xplang-install.md)

PostgreSQL 允許使用者定義的函式以 SQL 與 C 以外的其他語言撰寫。這些其他語言統稱為*程序語言*（procedural languages，PLs）。對於以程序語言撰寫的函式，資料庫伺服器並沒有內建關於如何解讀該函式原始碼文字的知識，而是把這項工作交給一個了解該語言細節的特殊處理常式。這個處理常式可以自行完成剖析、語法分析、執行等所有工作，也可以作為 PostgreSQL 與某個既有程式語言實作之間的「膠水」。處理常式本身是一個以 C 語言撰寫的函式，編譯成共用物件並依需要載入，就和其他任何 C 函式一樣。

PostgreSQL 標準發行版目前提供四種程序語言：PL/pgSQL（[第 41 章](https://docs.postgresql.tw/19/server-programming/plpgsql.md)）、PL/Tcl（[第 42 章](https://docs.postgresql.tw/19/server-programming/pltcl.md)）、PL/Perl（[第 43 章](https://docs.postgresql.tw/19/server-programming/plperl.md)）與 PL/Python（[第 44 章](https://docs.postgresql.tw/19/server-programming/plpython.md)）。另外還有一些未包含在核心發行版中的程序語言可供使用，[附錄 H](https://docs.postgresql.tw/19/appendixes/external-projects.md) 有如何找到它們的資訊。此外，使用者也可以自行定義其他語言；開發新程序語言的基礎知識涵蓋於[第 57 章](https://docs.postgresql.tw/19/internals/plhandler.md)。

***

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


---

# 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/xplang.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.
