# 8.21. 概念型別

PostgreSQL 型別系統包含許多專用項目，這些項目統稱為概念型別(pseudo-type)。概念型別不能用作實際的欄位資料型別，但可以用來宣告函數的參數或結果型別。各個概念型別在於函數的行為不只是對應於簡單地獲取或回傳特定 SQL 資料型別的值的情況下很有用。Table 8.27 列出了現有的概念型別。

#### **Table 8.27. Pseudo-Types**

| Name               | Description                                                                                                                                                                                                                                |
| ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `any`              | Indicates that a function accepts any input data type.                                                                                                                                                                                     |
| `anyelement`       | Indicates that a function accepts any data type (see [Section 37.2.5](https://www.postgresql.org/docs/12/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC)).                                                                               |
| `anyarray`         | Indicates that a function accepts any array data type (see [Section 37.2.5](https://www.postgresql.org/docs/12/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC)).                                                                         |
| `anynonarray`      | Indicates that a function accepts any non-array data type (see [Section 37.2.5](https://www.postgresql.org/docs/12/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC)).                                                                     |
| `anyenum`          | Indicates that a function accepts any enum data type (see [Section 37.2.5](https://www.postgresql.org/docs/12/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC) and [Section 8.7](https://www.postgresql.org/docs/12/datatype-enum.html)). |
| `anyrange`         | Indicates that a function accepts any range data type (see [Section 37.2.5](https://www.postgresql.org/docs/12/extend-type-system.html#EXTEND-TYPES-POLYMORPHIC) and [Section 8.17](https://www.postgresql.org/docs/12/rangetypes.html)).  |
| `cstring`          | Indicates that a function accepts or returns a null-terminated C string.                                                                                                                                                                   |
| `internal`         | Indicates that a function accepts or returns a server-internal data type.                                                                                                                                                                  |
| `language_handler` | A procedural language call handler is declared to return `language_handler`.                                                                                                                                                               |
| `fdw_handler`      | A foreign-data wrapper handler is declared to return `fdw_handler`.                                                                                                                                                                        |
| `index_am_handler` | An index access method handler is declared to return `index_am_handler`.                                                                                                                                                                   |
| `tsm_handler`      | A tablesample method handler is declared to return `tsm_handler`.                                                                                                                                                                          |
| `record`           | Identifies a function taking or returning an unspecified row type.                                                                                                                                                                         |
| `trigger`          | A trigger function is declared to return `trigger.`                                                                                                                                                                                        |
| `event_trigger`    | An event trigger function is declared to return `event_trigger.`                                                                                                                                                                           |
| `pg_ddl_command`   | Identifies a representation of DDL commands that is available to event triggers.                                                                                                                                                           |
| `void`             | Indicates that a function returns no value.                                                                                                                                                                                                |
| `unknown`          | Identifies a not-yet-resolved type, e.g. of an undecorated string literal.                                                                                                                                                                 |
| `opaque`           | An obsolete type name that formerly served many of the above purposes.                                                                                                                                                                     |

Functions coded in C (whether built-in or dynamically loaded) can be declared to accept or return any of these pseudo data types. It is up to the function author to ensure that the function will behave safely when a pseudo-type is used as an argument type.

Functions coded in procedural languages can use pseudo-types only as allowed by their implementation languages. At present most procedural languages forbid use of a pseudo-type as an argument type, and allow only `void` and `record` as a result type (plus `trigger` or `event_trigger` when the function is used as a trigger or event trigger). Some also support polymorphic functions using the types `anyelement`, `anyarray`, `anynonarray`, `anyenum`, and `anyrange`.

The `internal` pseudo-type is used to declare functions that are meant only to be called internally by the database system, and not by direct invocation in an SQL query. If a function has at least one `internal`-type argument then it cannot be called from SQL. To preserve the type safety of this restriction it is important to follow this coding rule: do not create any function that is declared to return `internal` unless it has at least one `internal` argument.<br>


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.postgresql.tw/13/the-sql-language/data-types/pseudo-types.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
