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

# 第 58 章 撰寫外部資料包裝器

### 第 58 章 撰寫外部資料包裝器

**目錄**

* [58.1. 外部資料包裝器函式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-functions.md)
* [58.2. 外部資料包裝器回呼常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md)
  * [58.2.1. 掃描外部資料表的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-scan)
  * [58.2.2. 掃描外部資料表連接的 FDW 函式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-join-scan)
  * [58.2.3. 規劃掃描／連接後處理的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-upper-planning)
  * [58.2.4. 更新外部資料表的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-update)
  * [58.2.5. `TRUNCATE` 的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-truncate)
  * [58.2.6. 資料列鎖定的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-row-locking)
  * [58.2.7. `EXPLAIN` 的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-explain)
  * [58.2.8. `ANALYZE` 的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-analyze)
  * [58.2.9. `IMPORT FOREIGN SCHEMA` 的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-import)
  * [58.2.10. 平行執行的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-parallel)
  * [58.2.11. 非同步執行的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-async)
  * [58.2.12. 路徑重新參數化的 FDW 常式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-callbacks.md#fdw-callbacks-reparameterize-paths)
* [58.3. 外部資料包裝器輔助函式](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-helpers.md)
* [58.4. 外部資料包裝器查詢規劃](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-planning.md)
* [58.5. 外部資料包裝器中的資料列鎖定](https://docs.postgresql.tw/19/internals/fdwhandler/fdw-row-locking.md)

對外部資料表的所有操作，都是透過其外部資料包裝器處理；外部資料包裝器由一組供核心伺服器呼叫的函式組成。外部資料包裝器負責從遠端資料來源擷取資料，並將資料傳回給 PostgreSQL 執行器。如果要支援更新外部資料表，包裝器也必須處理這部分。本章概述如何撰寫新的外部資料包裝器。

嘗試撰寫自己的外部資料包裝器時，標準發行版中所附的外部資料包裝器是很好的參考。請查看原始碼樹中的 `contrib` 子目錄。[CREATE FOREIGN DATA WRAPPER](https://docs.postgresql.tw/19/reference/sql-commands/sql-createforeigndatawrapper.md) 參考頁面也有一些實用的細節。

#### 注意

SQL 標準規定了一套撰寫外部資料包裝器的介面。然而，PostgreSQL 並未實作該 API，因為要將它納入 PostgreSQL 的工作量會很大，而且該標準 API 本來就沒有獲得廣泛採用。

***

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


---

# 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/internals/fdwhandler.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.
