Postgresql 中文操作指南

Chapter 42. Procedural Languages

Table of Contents

PostgreSQL 允许用户使用 SQL 和 C 以外的其他语言编写用户定义函数。泛型称这些其他语言为 procedural languages (PL)。对于用过程语言编写的函数,数据库服务器不会内置解释函数源文本的方法。相反,此任务将传递给一个知道该语言详细信息的专门处理程序。该处理程序可以自己完成所有解析、语法分析、执行等工作,或者它可以用作 PostgreSQL 和编程语言现有实现之间的“胶合剂”。该处理程序本身就是编译为共享对象并根据需要加载的 C 语言函数,就像任何其他 C 函数一样。

PostgreSQL allows user-defined functions to be written in other languages besides SQL and C. These other languages are generically called procedural languages (PLs). For a function written in a procedural language, the database server has no built-in knowledge about how to interpret the function’s source text. Instead, the task is passed to a special handler that knows the details of the language. The handler could either do all the work of parsing, syntax analysis, execution, etc. itself, or it could serve as “glue” between PostgreSQL and an existing implementation of a programming language. The handler itself is a C language function compiled into a shared object and loaded on demand, just like any other C function.

标准 PostgreSQL 发行版当前提供四种过程语言:PL/pgSQL ( Chapter 43 )、PL/Tcl ( Chapter 44 )、PL/Perl ( Chapter 45 ) 和 PL/Python ( Chapter 46 )。有其他未包含在核心发行版中的过程语言可供使用。 Appendix H 有一些关于在何处查找这些语言的信息。此外,用户还可以定义其他语言; Chapter 58 中介绍了开发新过程语言的基础知识。

There are currently four procedural languages available in the standard PostgreSQL distribution: PL/pgSQL (Chapter 43), PL/Tcl (Chapter 44), PL/Perl (Chapter 45), and PL/Python (Chapter 46). There are additional procedural languages available that are not included in the core distribution. Appendix H has information about finding them. In addition other languages can be defined by users; the basics of developing a new procedural language are covered in Chapter 58.