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

# 8.21. 虛擬型別 \#

### 8.21. 虛擬型別 [#](#datatype-pseudo) <a href="#datatype-pseudo" id="datatype-pseudo"></a>

PostgreSQL 的型別系統中包含許多特殊用途的項目，它們統稱為*虛擬型別*。虛擬型別不能作為欄位的資料型別使用，但可以用來宣告函式的引數型別或結果型別。當函式的行為並非單純地接受或回傳某個特定 SQL 資料型別的值時，各種可用的虛擬型別就能派上用場。[表 8.27](#datatype-pseudo-table) 列出現有的虛擬型別。

#### 表 8.27. 虛擬型別 [#](#datatype-pseudo-table) <a href="#datatype-pseudo-table" id="datatype-pseudo-table"></a>

| 名稱                        | 說明                                                                                                                                                                                                                                                                       |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `any`                     | 表示函式接受任何輸入資料型別。                                                                                                                                                                                                                                                          |
| `anyelement`              | 表示函式接受任何資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                                          |
| `anyarray`                | 表示函式接受任何陣列資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                                        |
| `anynonarray`             | 表示函式接受任何非陣列資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                                       |
| `anyenum`                 | 表示函式接受任何列舉資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)與[第 8.7 節](https://docs.postgresql.tw/19/the-sql-language/datatype/datatype-enum.md)）。                    |
| `anyrange`                | 表示函式接受任何範圍資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)與[第 8.17 節](https://docs.postgresql.tw/19/the-sql-language/datatype/rangetypes.md)）。                      |
| `anymultirange`           | 表示函式接受任何多重範圍資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)與[第 8.17 節](https://docs.postgresql.tw/19/the-sql-language/datatype/rangetypes.md)）。                    |
| `anycompatible`           | 表示函式接受任何資料型別，並自動把多個引數提升為共同的資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                       |
| `anycompatiblearray`      | 表示函式接受任何陣列資料型別，並自動把多個引數提升為共同的資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                     |
| `anycompatiblenonarray`   | 表示函式接受任何非陣列資料型別，並自動把多個引數提升為共同的資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)）。                                                                                    |
| `anycompatiblerange`      | 表示函式接受任何範圍資料型別，並自動把多個引數提升為共同的資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)與[第 8.17 節](https://docs.postgresql.tw/19/the-sql-language/datatype/rangetypes.md)）。   |
| `anycompatiblemultirange` | 表示函式接受任何多重範圍資料型別，並自動把多個引數提升為共同的資料型別（請參閱[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)與[第 8.17 節](https://docs.postgresql.tw/19/the-sql-language/datatype/rangetypes.md)）。 |
| `cstring`                 | 表示函式接受或回傳以 null 結尾的 C 字串。                                                                                                                                                                                                                                                |
| `internal`                | 表示函式接受或回傳伺服器內部的資料型別。                                                                                                                                                                                                                                                     |
| `language_handler`        | 程序語言的呼叫處理常式被宣告為回傳 `language_handler`。                                                                                                                                                                                                                                    |
| `fdw_handler`             | 外部資料包裝器的處理常式被宣告為回傳 `fdw_handler`。                                                                                                                                                                                                                                        |
| `table_am_handler`        | 資料表存取方法的處理常式被宣告為回傳 `table_am_handler`。                                                                                                                                                                                                                                   |
| `index_am_handler`        | 索引存取方法的處理常式被宣告為回傳 `index_am_handler`。                                                                                                                                                                                                                                    |
| `tsm_handler`             | tablesample 方法的處理常式被宣告為回傳 `tsm_handler`。                                                                                                                                                                                                                                 |
| `record`                  | 識別接受或回傳未指定之資料列型別的函式。                                                                                                                                                                                                                                                     |
| `trigger`                 | 觸發程序函式被宣告為回傳 `trigger.`                                                                                                                                                                                                                                                  |
| `event_trigger`           | 事件觸發程序函式被宣告為回傳 `event_trigger.`                                                                                                                                                                                                                                          |
| `pg_ddl_command`          | 識別可供事件觸發程序使用的 DDL 指令表示法。                                                                                                                                                                                                                                                 |
| `void`                    | 表示函式不回傳任何值。                                                                                                                                                                                                                                                              |
| `unknown`                 | 識別尚未解析的型別，例如未加修飾之字串常數的型別。                                                                                                                                                                                                                                                |

<br>

以 C 撰寫的函式（無論是內建的還是動態載入的）都可以宣告為接受或回傳這些虛擬型別中的任何一種。至於當虛擬型別被用作引數型別時，函式是否能安全運作，則由函式的作者負責確保。

以程序語言撰寫的函式，只能在其實作語言所允許的範圍內使用虛擬型別。目前大多數程序語言都禁止把虛擬型別用作引數型別，而結果型別只允許 `void` 與 `record`（當函式被用作觸發程序或事件觸發程序時，還可加上 `trigger` 或 `event_trigger`）。有些程序語言也支援使用多型虛擬型別的多型函式，這些型別如上表所示，並在[第 36.2.5 節](https://docs.postgresql.tw/19/server-programming/extend/extend-type-system/extend-types-polymorphic.md#extend-types-polymorphic)中有詳細討論。

`internal` 虛擬型別用來宣告那些只打算由資料庫系統內部呼叫、而不應在 SQL 查詢中直接叫用的函式。如果某個函式至少有一個 `internal` 型別的引數，它就無法從 SQL 呼叫。為了維持這項限制所提供的型別安全，遵守下列撰寫規則很重要：除非函式至少有一個 `internal` 引數，否則不要建立任何宣告為回傳 `internal` 的函式。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/datatype-pseudo.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/the-sql-language/datatype/datatype-pseudo.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.
