create_language.7
来自「PostgreSQL 8.2中增加了很多企业用户所需要的功能和性能上的提高,其开」· 7 代码 · 共 164 行
7
164 行
.\\" auto-generated by docbook2man-spec $Revision: 1.1.1.1 $.TH "CREATE LANGUAGE" "" "2008-01-03" "SQL - Language Statements" "SQL Commands".SH NAMECREATE LANGUAGE \- define a new procedural language.SH SYNOPSIS.sp.nfCREATE [ PROCEDURAL ] LANGUAGE \fIname\fRCREATE [ TRUSTED ] [ PROCEDURAL ] LANGUAGE \fIname\fR HANDLER \fIcall_handler\fR [ VALIDATOR \fIvalfunction\fR ].sp.fi.SH "DESCRIPTION".PPUsing \fBCREATE LANGUAGE\fR, aPostgreSQL user can register a newprocedural language with a PostgreSQLdatabase. Subsequently, functions and trigger procedures can bedefined in this new language. The user must have thePostgreSQL superuser privilege toregister a new language..PP\fBCREATE LANGUAGE\fR effectively associates thelanguage name with a call handler that is responsible for executingfunctions written in the language. Refer to in the documentationfor more information about language call handlers..PPThere are two forms of the \fBCREATE LANGUAGE\fR command.In the first form, the user supplies just the name of the desiredlanguage, and the PostgreSQL server consultsthe \fBpg_pltemplate\fRsystem catalog to determine the correct parameters. In the second form,the user supplies the language parameters along with the language name.The second form can be used to create a language that is not defined in\fBpg_pltemplate\fR, but this approach is considered obsolescent..PPWhen the server finds an entry in the \fBpg_pltemplate\fR catalogfor the given language name, it will use the catalog data even if thecommand includes language parameters. This behavior simplifies loading ofold dump files, which are likely to contain out-of-date informationabout language support functions..SH "PARAMETERS".TP\fBTRUSTED\fRTRUSTED specifies that the call handler forthe language is safe, that is, it does not offer anunprivileged user any functionality to bypass accessrestrictions. If this key word is omitted when registering thelanguage, only users with thePostgreSQL superuser privilege canuse this language to create new functions..TP\fBPROCEDURAL\fRThis is a noise word..TP\fB\fIname\fB\fRThe name of the new procedural language. The language name iscase insensitive. The name must be unique among the languagesin the database.For backward compatibility, the name may be enclosed by singlequotes..TP\fBHANDLER \fIcall_handler\fB\fR\fIcall_handler\fR isthe name of a previously registered function that will becalled to execute the procedural language functions. The callhandler for a procedural language must be written in a compiledlanguage such as C with version 1 call convention andregistered with PostgreSQL as afunction taking no arguments and returning the\fBlanguage_handler\fR type, a placeholder type that issimply used to identify the function as a call handler..TP\fBVALIDATOR \fIvalfunction\fB\fR\fIvalfunction\fR is thename of a previously registered function that will be calledwhen a new function in the language is created, to validate thenew function.If novalidator function is specified, then a new function will notbe checked when it is created.The validator function must take one argument oftype \fBoid\fR, which will be the OID of theto-be-created function, and will typically return \fBvoid\fR.A validator function would typically inspect the function bodyfor syntactical correctness, but it can also look at otherproperties of the function, for example if the language cannothandle certain argument types. To signal an error, thevalidator function should use the \fBereport()\fRfunction. The return value of the function is ignored..PPThe TRUSTED option and the support function name(s) areignored if the server has an entry for the specified languagename in \fBpg_pltemplate\fR..PP.SH "NOTES".PPThe \fBcreatelang\fR(1) program is a simple wrapper aroundthe \fBCREATE LANGUAGE\fR command. It easesinstallation of procedural languages from the shell command line..PPUse DROP LANGUAGE [\fBdrop_language\fR(7)], or better yet the \fBdroplang\fR(1) program, to drop procedural languages..PPThe system catalog \fBpg_language\fR (see in the documentation) records information about thecurrently installed languages. Also, \fBcreatelang\fRhas an option to list the installed languages..PPTo create functions in a procedural language, a user must have theUSAGE privilege for the language. By default,USAGE is granted to PUBLIC (i.e., everyone)for trusted languages. This may be revoked if desired..PPProcedural languages are local to individual databases.However, a language can be installed into the template1database, which will cause it to be available automatically inall subsequently-created databases..PPThe call handler function and the validator function (if any)must already exist if the server does not have an entry for the languagein \fBpg_pltemplate\fR. But when there is an entry,the functions need not already exist;they will be automatically defined if not present in the database.(This can result in \fBCREATE LANGUAGE\fR failing, if theshared library that implements the language is not available inthe installation.).PPIn PostgreSQL versions before 7.3, it wasnecessary to declare handler functions as returning the placeholdertype \fBopaque\fR, rather than \fBlanguage_handler\fR.To support loading of old dump files, \fBCREATE LANGUAGE\fR will accept a functiondeclared as returning \fBopaque\fR, but it will issue a notice andchange the function's declared return type to \fBlanguage_handler\fR..SH "EXAMPLES".PPThe preferred way of creating any of the standard procedural languagesis just:.sp.nfCREATE LANGUAGE plpgsql;.sp.fi.PPFor a language not known in the \fBpg_pltemplate\fR catalog, asequence such as this is needed:.sp.nfCREATE FUNCTION plsample_call_handler() RETURNS language_handler AS '$libdir/plsample' LANGUAGE C;CREATE LANGUAGE plsample HANDLER plsample_call_handler;.sp.fi.SH "COMPATIBILITY".PP\fBCREATE LANGUAGE\fR is aPostgreSQL extension..SH "SEE ALSO"ALTER LANGUAGE [\fBalter_language\fR(7)], CREATE FUNCTION [\fBcreate_function\fR(l)], DROP LANGUAGE [\fBdrop_language\fR(l)], GRANT [\fBgrant\fR(l)], REVOKE [\fBrevoke\fR(l)], createlang [\fBcreatelang\fR(1)], droplang [\fBdroplang\fR(1)]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?