PostgreSQL 提供了四种类型的函数:
查询语言函数(使用 SQL 编写的函数,参见 Section 36.5)
过程语言函数(使用诸如 PL/pgSQL 或 PL/Tcl 等编写的函数,参见 Section 36.8)
内部函数(静态编译入内核内部的函数,参见 Section 36.9)
C 语言函数(动态链接加载的 C 函数,参见 Section 36.10)
各类函数均可接受基本数据类型、复合类型或其组合作为输入参数。此外,各类函数均可返回基本类型或复合类型结果。函数亦可定义为返回基本类型或复合类型的数据行集合(表函数)。
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.