PostgreSQL 18 中文参考文档(未翻译部分保留英文)🌐 切换到英文原版 →

36.3. 用户自定义函数 #

PostgreSQL 提供了四种类型的函数:

各类函数均可接受基本数据类型、复合类型或其组合作为输入参数。此外,各类函数均可返回基本类型或复合类型结果。函数亦可定义为返回基本类型或复合类型的数据行集合(表函数)。

Many kinds of functions can take or return certain pseudo-types (such as polymorphic types), but the available facilities vary. Consult the description of each kind of function for more details.

It's easiest to define SQL functions, so we'll start by discussing those. Most of the concepts presented for SQL functions will carry over to the other types of functions.

Throughout this chapter, it can be useful to look at the reference page of the CREATE FUNCTION command to understand the examples better. Some examples from this chapter can be found in funcs.sql and funcs.c in the src/tutorial directory in the PostgreSQL source distribution.