CREATE LANGUAGE

Name

CREATE LANGUAGE  --  Defines a new language for functions 関数用に新規言語を定義します。

Synopsis

CREATE [ TRUSTED ] PROCEDURAL LANGUAGE 'langname'
    HANDLER call_handler
    LANCOMPILER 'comment'
  

入力

TRUSTED

TRUSTED specifies that the call handler for the language is safe; that is, it offers an unprivileged user no functionality to bypass access restrictions. If this keyword is omitted when registering the language, only users with the Postgres superuser privilege can use this language to create new functions (like the 'C' language).

TRUSTED はその言語に対する呼び出し ハンドラが安全であることを指定します。すなわち、 権限のないユーザがアクセス制限を迂回出来ないようにする 機能です。言語登録の時、このキーワードが省略されると Postgres のスーパユーザ権限 を持つユーザのみ、新しい関数を生成するこの言語 ('C' 言語のように)を使用することが出来ます。

langname

The name of the new procedural language. The language name is case insensitive. A procedural language cannot override one of the built-in languages of Postgres.

新しい手続き言語の名前です。 言語名は大文字・小文字を区別します。手続き言語は Postgres に組み込まれている 言語のうち一つも上書きしません。

HANDLER call_handler

call_handler is the name of a previously registered function that will be called to execute the PL procedures.

call_handler は PL プロシージャを実行するために呼び出される、登録済の 関数の名前です。

comment

The LANCOMPILER argument is the string that will be inserted in the LANCOMPILER attribute of the new pg_language entry. At present, Postgres does not use this attribute in any way.

LANCOMPILER 引数は、新規の pg_language 項目の LANCOMPILER 属性に挿入される 文字列です。 とは言っても、現時点で Postgres は この属性を使用しません。

出力

CREATE

This message is returned if the language is successfully created.

言語が正常に作成されたときに戻るメッセージです。

ERROR: PL handler function funcname() doesn't exist

This error is returned if the function funcname() is not found.

関数 funcname() が見付からなかった場合に返されるエラーです。

説明

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

CREATE LANGUAGE によって、 Postgres ユーザは Postgres に新しい言語を登録 することが出来ます。 そうすると、その新規言語を用いて関数やトリガプロシージャを 定義することが出来ます。新規言語を登録するためには Postgres のスーパユーザの 権限が必要です。

PL ハンドラを書くには

The call handler for a procedural language must be written in a compiler language such as 'C' and registered with Postgres as a function taking no arguments and returning the opaque type, a placeholder for unspecified or undefined types.. This prevents the call handler from being called directly as a function from queries.

手続き言語用の呼び出しハンドラは 'C' のようなコンパイラ言語 で書かれ、Postgres に引数を取らずに opaque 型、指定されていないか定義されていない型を戻 す関数として登録されなければなりません。これは、問合せから 関数として呼び出しハンドラが直接呼び出されることを防ぐものです。

However, arguments must be supplied on the actual call when a PL function or trigger procedure in the language offered by the handler is to be executed.

とは言っても、ハンドラによって提供される言語を用いた PL 関数または トリガプロシージャが実行される場合、実際の呼び出しにおいて引数が 与えられなければなりません。

It's up to the call handler to fetch the pg_proc entry and to analyze the argument and return types of the called procedure. The AS clause from the CREATE FUNCTION of the procedure will be found in the prosrc attribute of the pg_proc table entry. This may be the source text in the procedural language itself (like for PL/Tcl), a pathname to a file or anything else that tells the call handler what to do in detail.

pg_proc 項目の取り出し、および、呼び出さ れたプロシージャの引数と戻される型の分析は、呼び出しハンドラに 依存します。 プロシージャの CREATE FUNCTION の AS 句は、pg_proc テーブル項目の prosrc 属性の中にあります。 これは、( PL/Tcl に対するような)手続き言語のソース原文 そのものであったり、あるファイルへのパス名であったり、 あるいは呼び出しハンドラが細部で何を行うのかを通知する なんらかのものであったりします。

注意事項

Use CREATE FUNCTION to create a function.

関数を作成するには CREATE FUNCTION を 使います。

Use DROP LANGUAGE to drop procedural languages.

手続き言語を削除するには DROP LANGUAGE を使います。

Refer to the table pg_language for further information:

より詳しい情報は、テーブル pg_language を参照して下さい。

     Table    = pg_language
+--------------------------+--------------------------+-------+
|          Field           |          Type            | Length|
+--------------------------+--------------------------+-------+
| lanname                  | name                     |    32 |
| lancompiler              | text                     |   var |
+--------------------------+--------------------------+-------+

lanname |lancompiler   
--------+--------------
internal|n/a           
lisp    |/usr/ucb/liszt
C       |/bin/cc       
sql     |postgres
     
    

制約事項

Since the call handler for a procedural language must be registered with Postgres in the 'C' language, it inherits all the capabilities and restrictions of 'C' functions.

手続き言語に対する呼び出しハンドラは 'C' 言語で Postgres に登録されなければ なりませんので、 'C' 関数の全ての機能と制約事項が継承 されます。

バグ情報

At present, the definitions for a procedural language cannot be changed once they have been created.

現在では、一度作成されてしまった手続き言語の定義を変更する ことが出来ません。

使用法

This is a template for a PL handler written in 'C':

以下は 'C' で書かれた PL ハンドラ用の雛型です。

#include "executor/spi.h"
#include "commands/trigger.h"
#include "utils/elog.h"
#include "fmgr.h"        /* for FmgrValues struct */
#include "access/heapam.h"
#include "utils/syscache.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"

Datum
plsample_call_handler(
     Oid       prooid,
     int       pronargs,
     FmgrValues     *proargs,
     bool      *isNull)
{
     Datum          retval;
     TriggerData    *trigdata;

     if (CurrentTriggerData == NULL) {
          /*
           * Called as a function
           */

          retval = ...
     } else {
          /*
           * Called as a trigger procedure
           */
          trigdata = CurrentTriggerData;
          CurrentTriggerData = NULL;

          retval = ...
     }

     *isNull = false;
     return retval;
}
   

Only a few thousand lines of code have to be added instead of the dots to complete the PL call handler. See CREATE FUNCTION for information on how to compile it into a loadable module.

PL 呼び出しハンドラを完結させるには些細ことではなく、 実際は数千行のコードを追加しなければなりません。 読み込み可能モジュールにコンパイルする情報については CREATE FUNCTION を参照して下さい。

The following commands then register the sample procedural language:

以下のコマンドで手続き言語の例を登録します:

CREATE FUNCTION plsample_call_handler () RETURNS opaque
    AS '/usr/local/pgsql/lib/plsample.so'
    LANGUAGE 'C';
CREATE PROCEDURAL LANGUAGE 'plsample'
    HANDLER plsample_call_handler
    LANCOMPILER 'PL/Sample';
   

互換性

CREATE LANGUAGE is a Postgres extension.

CREATE LANGUAGE は Postgres の 拡張です。

SQL92

There is no CREATE LANGUAGE statement in SQL92.

SQL92CREATE LANGUAGE 文はありません。