8.21. Pseudo-Types

8.21. Pseudo-Types

8.21.伪类型

The PostgreSQL type system contains a number of special-purpose entries that are collectively called pseudo-types. A pseudo-type cannot be used as a column data type, but it can be used to declare a function's argument or result type. Each of the available pseudo-types is useful in situations where a function's behavior does not correspond to simply taking or returning a value of a specific SQL data type. Table 8.25 lists the existing pseudo-types.

PostgreSQL类型系统包含许多特殊用途的条目,这些条目统称为伪类型。 伪类型不能用作列数据类型,但可以用来声明函数的参数或结果类型。每个可用的伪类型在函数的行为不仅仅对应于获取或返回特定SQL数据类型的值的情况下很有用。 表8.25列出了现有的伪类型。

 

uploading.4e448015.gif转存失败重新上传取消

uploading.4e448015.gif转存失败重新上传取消

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.

用C编码的函数(无论是内置的还是动态加载的)可以接受或返回任何这些伪数据类型。函数编写者有责任确保在将伪类型用作参数类型时该函数将安全地运行。

 

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.

用过程语言编码的函数只能在其实现语言允许的情况下使用伪类型。 目前,大多数程序语言都禁止将伪类型用作参数类型,并且仅允许将void和record作为结果类型(当将函数用作触发器或事件触发器时,则添加trigger或event_trigger)。 一些还使用类型anyelement,anyarray,anynonarray,anyenum和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.

内部伪类型用于声明仅在数据库系统内部进行调用的函数,而不是在SQL查询中直接调用的函数。 如果一个函数至少有一个内部类型参数,则不能从SQL调用它。 为了保持此限制的类型安全性,请务必遵循此编码规则:请勿创建任何声明为返回内部函数的函数,除非该函数至少具有一个内部参数。

你可能感兴趣的:(PostgreSQL,11.2用户手册学习,postgresql)