CREATE LANGUAGE 中文man页面

系统
使用 CREATE LANGUAGE, 一个PostgreSQL 用户可以在 PostgreSQL里注册一个新的语言。 因而,函数和触发器过程可以用这种新语言定义。要注册新语言用户必须具有 PostgreSQL 超级用户权限。

NAME

CREATE LANGUAGE - 定义一种新的过程语言

SYNOPSIS

CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
    HANDLER call_handler [ VALIDATOR valfunction ]

DESCRIPTION 描述


 使用 CREATE LANGUAGE, 一个PostgreSQL 用户可以在 PostgreSQL里注册一个新的语言。 因而,函数和触发器过程可以用这种新语言定义。要注册新语言用户必须具有 PostgreSQL 超级用户权限。

CREATE LANGUAGE 将该语言的名字和一个调用句柄关联起来,而该调用句柄负责执行该语言书写的函数。 请参考 ``User-Defined Functions'' 获取有关语言调用句柄的更多信息。


 请注意过程语言是对每个独立的数据库而言是自己的。 要让一种语言缺省时可以为所有数据库获得,那你应该把它安装到 template1 数据库里。  

PARAMETERS 参数

TRUSTED
TRUSTED 说明对该语言的调用句柄是安全的; 也就是说,它不会提供给非特权用户任何绕过访问限制的能力。 如果忽略这个关键字,只有具有 PostgreSQL 超级用户权限的人可以使用这个语言创建新的函数。
PROCEDURAL

 这是个没有用的字。
name

 新的过程化语言的名称。语言名是大小写无关的。 这个名字应该在数据库的所有语言中***。


 出于向下兼容的原因,这个名字可以用单引号包围。

HANDLER call_handler
call_handler 是一个以前注册过的函数的名字,该函数将被调用来执行这门过程语言写的函数。 过程语言的调用句柄必须用一种编译语言书写,比如 C,调用风格必须是版本 1 的调用风格, 并且在 PostgreSQL 里注册为不接受参数并且返回 language_handler 类型的函数, language_handler 是用于将函数声明为调用句柄的占位符。
VALIDATOR valfunction
valfunction 是一个已经注册的函数的名字, 在用该语言创建新函数的时候将调用它来校验新函数。如果没有声明校验函数,那么建立新函数的时候就不会检查它。 校验函数必须接受一个类型为 oid 的参数,它是将要创建的函数的 OID,并且通常会返回 void。


 校验函数通常会检查函数体,看看看有没有语法错误,但是它也可以查看函数的其它属性, 比如该语言是否不能处理某种参数类型。要发出一个错误,校验函数应该用 elog() 函数。 该函数的返回值将被忽略。

NOTES 注意


 这条命令通常不应该由用户直接执行。 对于 PostgreSQL 版本里提供的过程语言, 我们应该使用 createlang(1) 程序, 它将为我们安装正确的调用句柄。 (createlang 也会在内部调用 CREATE LANGUAGE。)


 在 PostgreSQL 版本 7.3 之前, 我们必须声明句柄函数返回占位类型 opaque,而不是 language_handler。 为了支持装载旧的转储文件,CREATE LANGUAGE 还将接受声明为返回 opaque 的函数, 但是它会发出一条通知并且把函数声明返回类型改为 language_handler。


 使用 CREATE FUNCTION [create_function(7)] 命令创建新函数。


 使用 DROP LANGUAGE [drop_language(7)],或者更好是 droplang(1) 程序删除一个过程语言。


 系统表 pg_language (参阅 ``System Catalogs'') 记录了更多有关当前安装的过程语言的信息。createlang 也有一个选项列出已安装的语言。


 目前,除了权限之外,一种过程语言创建之后它的定义就不能再更改。


 要使用一种过程语言,用户必须被赋予 USAGE 权限。 如果该语言已知是可信的,那么 createlang 程序自动给每个人赋予权限。  

EXAMPLES 例子


 下面两条顺序执行的命令将注册一门新的过程语言及其关联的调用句柄。

CREATE FUNCTION plsample_call_handler() RETURNS language_handler
    AS '$libdir/plsample'
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;

COMPATIBILITY 兼容性

CREATE LANGUAGE 是 PostgreSQL 扩展。  

SEE ALSO 参见

ALTER LANGUAGE [alter_language(7)], CREATE FUNCTION [create_function(l)], DROP LANGUAGE [drop_language(l)], GRANT [grant(l)], REVOKE [revoke(l)], createlang(1), droplang(1)  

#p#

NAME

CREATE LANGUAGE - define a new procedural language

SYNOPSIS

CREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
    HANDLER call_handler [ VALIDATOR valfunction ]

DESCRIPTION

Using CREATE LANGUAGE, a PostgreSQL user can register a new procedural language with a PostgreSQL database. Subsequently, functions and trigger procedures can be defined in this new language. The user must have the PostgreSQL superuser privilege to register a new language.

CREATE LANGUAGE effectively associates the language name with a call handler that is responsible for executing functions written in the language. Refer to the section called ``User-Defined Functions'' in the documentation for more information about language call handlers.

Note that procedural languages are local to individual databases. To make a language available in all databases by default, it should be installed into the template1 database.  

PARAMETERS

TRUSTED
TRUSTED specifies that the call handler for the language is safe, that is, it does not offer an unprivileged user any functionality to bypass access restrictions. If this key word is omitted when registering the language, only users with the PostgreSQL superuser privilege can use this language to create new functions.
PROCEDURAL
This is a noise word.
name
The name of the new procedural language. The language name is case insensitive. The name must be unique among the languages in the database.

For backward compatibility, the name may be enclosed by single quotes.

HANDLER call_handler
call_handler is the name of a previously registered function that will be called to execute the procedural language functions. The call handler for a procedural language must be written in a compiled language such as C with version 1 call convention and registered with PostgreSQL as a function taking no arguments and returning the language_handler type, a placeholder type that is simply used to identify the function as a call handler.
VALIDATOR valfunction
valfunction is the name of a previously registered function that will be called when a new function in the language is created, to validate the new function. If no validator function is specified, then a new function will not be checked when it is created. The validator function must take one argument of type oid, which will be the OID of the to-be-created function, and will typically return void.

A validator function would typically inspect the function body for syntactical correctness, but it can also look at other properties of the function, for example if the language cannot handle certain argument types. To signal an error, the validator function should use the ereport() function. The return value of the function is ignored.

NOTES

This command normally should not be executed directly by users. For the procedural languages supplied in the PostgreSQL distribution, the createlang(1) program should be used, which will also install the correct call handler. (createlang will call CREATE LANGUAGE internally.)

In PostgreSQL versions before 7.3, it was necessary to declare handler functions as returning the placeholder type opaque, rather than language_handler. To support loading of old dump files, CREATE LANGUAGE will accept a function declared as returning opaque, but it will issue a notice and change the function's declared return type to language_handler.

Use the CREATE FUNCTION [create_function(7)] command to create a new function.

Use DROP LANGUAGE [drop_language(7)], or better yet the droplang(1) program, to drop procedural languages.

The system catalog pg_language (see the chapter called ``System Catalogs'' in the documentation) records information about the currently installed languages. Also createlang has an option to list the installed languages.

The definition of a procedural language cannot be changed once it has been created, with the exception of the privileges.

To be able to use a procedural language, a user must be granted the USAGE privilege. The createlang program automatically grants permissions to everyone if the language is known to be trusted.  

EXAMPLES

The following two commands executed in sequence will register a new procedural language and the associated call handler.

CREATE FUNCTION plsample_call_handler() RETURNS language_handler
    AS '$libdir/plsample'
    LANGUAGE C;
CREATE LANGUAGE plsample
    HANDLER plsample_call_handler;

COMPATIBILITY

CREATE LANGUAGE is a PostgreSQL extension.  

SEE ALSO

ALTER LANGUAGE [alter_language(7)], CREATE FUNCTION [create_function(l)], DROP LANGUAGE [drop_language(l)], GRANT [grant(l)], REVOKE [revoke(l)], createlang(1), droplang(1)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 14:31:48

DROP LANGUA中文man

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 10:46:36

CREATE AGGR中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:36:25

CREATE TRIG中文man

2011-08-24 13:32:56

CREATE TABL中文man

2011-08-24 09:32:13

alter_langu中文man

2011-08-24 11:02:11

CREATE DOMA中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 13:23:10

CREATE SCHE中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:10:17

CREATE GROU中文man

2011-08-24 11:23:20

CREATE OPER中文man

2011-08-24 11:31:47

CREATE RULE中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-25 14:07:55

create_modu中文man
点赞
收藏

51CTO技术栈公众号