バージョンごとのドキュメント一覧

42.1. 手続き言語のインストール #

<title>Installing Procedural Languages</title>

A procedural language must be <quote>installed</quote> into each database where it is to be used. But procedural languages installed in the database <literal>template1</literal> are automatically available in all subsequently created databases, since their entries in <literal>template1</literal> will be copied by <command>CREATE DATABASE</command>. So the database administrator can decide which languages are available in which databases and can make some languages available by default if desired. 手続き言語は、それらが使用されるデータベースすべてにインストールされている必要があります。 しかし、template1データベースにインストールされた手続き言語は、template1内の項目はCREATE DATABASEによってコピーされますので、その後に作成されたすべてのデータベースで自動的に使用できます。 したがって、データベース管理者はどのデータベースにどの言語を使用するかを決定できますし、デフォルトで使用できる言語も決定できます。

For the languages supplied with the standard distribution, it is only necessary to execute <command>CREATE EXTENSION</command> <replaceable>language_name</replaceable> to install the language into the current database. The manual procedure described below is only recommended for installing languages that have not been packaged as extensions. 標準配布物で提供される言語では、その言語を現在のデータベースにインストールするにはCREATE EXTENSION language_nameの実行のみが必要です。 下記の手作業は、拡張機能としてパッケージ化されていない言語をインストールする場合にのみ行うことを推奨します。

手続き言語の手作業によるインストール方法

<title>Manual Procedural Language Installation</title>

A procedural language is installed in a database in five steps, which must be carried out by a database superuser. In most cases the required SQL commands should be packaged as the installation script of an <quote>extension</quote>, so that <command>CREATE EXTENSION</command> can be used to execute them. 手続き言語を次の5段階でデータベースにインストールすることができます。 この作業はデータベースのスーパーユーザで行う必要があります。 ほとんどの場合、必要なSQLコマンドは拡張機能のインストールスクリプトとしてパッケージ化されていますので、この作業を実行するのにCREATE EXTENSIONが利用できます。

  1. The shared object for the language handler must be compiled and installed into an appropriate library directory. This works in the same way as building and installing modules with regular user-defined C functions does; see <xref linkend="dfunc"/>. Often, the language handler will depend on an external library that provides the actual programming language engine; if so, that must be installed as well. その言語ハンドラ用の共有オブジェクトがコンパイルされ、適切なライブラリディレクトリにインストールされている必要があります。 これは、通常のユーザ定義のC関数を使ってモジュールを構築しインストールする時と同じです。 38.10.5を参照してください。 実際のプログラミング言語エンジンを提供する外部ライブラリに、言語ハンドラが依存していることがよくあります。 この場合はそのライブラリもインストールしなければなりません。

  2. The handler must be declared with the command ハンドラは下記のコマンドで宣言されなければなりません。

    CREATE FUNCTION handler_function_name()
        RETURNS language_handler
        AS 'path-to-shared-object'
        LANGUAGE C;
    

    The special return type of <type>language_handler</type> tells the database system that this function does not return one of the defined <acronym>SQL</acronym> data types and is not directly usable in <acronym>SQL</acronym> statements. language_handlerという特別な戻り値の型は、この関数が定義済みのSQLデータ型を返さず、SQL文では直接使用できないことをデータベースシステムに伝えます。

  3. Optionally, the language handler can provide an <quote>inline</quote> handler function that executes anonymous code blocks (<link linkend="sql-do"><command>DO</command></link> commands) written in this language. If an inline handler function is provided by the language, declare it with a command like 省略可能ですが、言語ハンドラは、この言語で書かれた無名コードブロック(DOコマンド)を実行するインラインハンドラ関数を提供することができます。 インラインハンドラ関数が言語により提供されるのであれば、以下のようなコマンドで宣言されます。

    CREATE FUNCTION inline_function_name(internal)
        RETURNS void
        AS 'path-to-shared-object'
        LANGUAGE C;
    

  4. Optionally, the language handler can provide a <quote>validator</quote> function that checks a function definition for correctness without actually executing it. The validator function is called by <command>CREATE FUNCTION</command> if it exists. If a validator function is provided by the language, declare it with a command like 省略可能ですが、言語ハンドラは、実際に実行することなく関数定義の正確性を検査する有効性検査関数を提供することができます。 もし存在すれば、有効性検査関数はCREATE FUNCTIONで呼び出されます。 有効性検査関数が言語により提供されるのであれば、以下のようなコマンドで宣言されます。

    CREATE FUNCTION validator_function_name(oid)
        RETURNS void
        AS 'path-to-shared-object'
        LANGUAGE C STRICT;
    

  5. Finally, the PL must be declared with the command 最終的に、PLは下記のコマンドで宣言されなければいけません。

    CREATE [TRUSTED] LANGUAGE language_name
        HANDLER handler_function_name
        [INLINE inline_function_name]
        [VALIDATOR validator_function_name] ;
    

    The optional key word <literal>TRUSTED</literal> specifies that the language does not grant access to data that the user would not otherwise have. Trusted languages are designed for ordinary database users (those without superuser privilege) and allows them to safely create functions and procedures. Since PL functions are executed inside the database server, the <literal>TRUSTED</literal> flag should only be given for languages that do not allow access to database server internals or the file system. The languages <application>PL/pgSQL</application>, <application>PL/Tcl</application>, and <application>PL/Perl</application> are considered trusted; the languages <application>PL/TclU</application>, <application>PL/PerlU</application>, and <application>PL/PythonU</application> are designed to provide unlimited functionality and should <emphasis>not</emphasis> be marked trusted. TRUSTEDというオプションキーワードは、ユーザがアクセス権を持たないデータに対して、その言語がアクセス権を持たないことを指定します。 TRUSTEDである言語は(スーパーユーザ権限を持たない)一般ユーザ用に設計されており、安全に関数やプロシージャを作成できます。 PL関数はデータベースサーバの内部で実行されますので、TRUSTEDフラグはデータベースサーバ内部やファイルシステムへのアクセスを持たない言語のみが使わなければなりません。 PL/pgSQLPL/TclPL/Perl言語はTRUSTEDと考えられています。 提供される機能が無制限に設計されているPL/TclUPL/PerlUPL/PythonU言語については、TRUSTEDを指定してはなりません

<xref linkend="xplang-install-example"/> shows how the manual installation procedure would work with the language <application>PL/Perl</application>. 例 42.1に、手作業によるインストール手順がPL/Perl言語でどのように動作するかを示します。

例42.1 PL/Perlの手作業によるインストール

<title>Manual Installation of <application>PL/Perl</application></title>

The following command tells the database server where to find the shared object for the <application>PL/Perl</application> language's call handler function: 以下のコマンドは、データベースサーバにPL/Perl言語の呼び出しハンドラ関数用の共有ライブラリの存在場所を通知します。

CREATE FUNCTION plperl_call_handler() RETURNS language_handler AS
    '$libdir/plperl' LANGUAGE C;

<application>PL/Perl</application> has an inline handler function and a validator function, so we declare those too: PL/Perlはインラインハンドラ関数と有効性検査関数を有していますので、以下のようにも宣言します。

CREATE FUNCTION plperl_inline_handler(internal) RETURNS void AS
    '$libdir/plperl' LANGUAGE C STRICT;

CREATE FUNCTION plperl_validator(oid) RETURNS void AS
    '$libdir/plperl' LANGUAGE C STRICT;

The command: 以下のコマンドは、

CREATE TRUSTED LANGUAGE plperl
    HANDLER plperl_call_handler
    INLINE plperl_inline_handler
    VALIDATOR plperl_validator;

then defines that the previously declared functions should be invoked for functions and procedures where the language attribute is <literal>plperl</literal>. 直前に宣言された関数を、言語属性がplperlである関数やプロシージャ用に呼び出さなければならないことを定義します。


In a default <productname>PostgreSQL</productname> installation, the handler for the <application>PL/pgSQL</application> language is built and installed into the <quote>library</quote> directory; furthermore, the <application>PL/pgSQL</application> language itself is installed in all databases. If <application>Tcl</application> support is configured in, the handlers for <application>PL/Tcl</application> and <application>PL/TclU</application> are built and installed in the library directory, but the language itself is not installed in any database by default. Likewise, the <application>PL/Perl</application> and <application>PL/PerlU</application> handlers are built and installed if Perl support is configured, and the <application>PL/PythonU</application> handler is installed if Python support is configured, but these languages are not installed by default. デフォルトのPostgreSQLインストレーションでは、PL/pgSQL言語用のハンドラは構築され、ライブラリディレクトリにインストールされます。 さらに、PL/pgSQL言語自体がデータベースすべてにインストールされます。 Tclのサポート付きで構築した場合、PL/TclPL/TclU用のハンドラも構築されライブラリディレクトリにインストールされますが、言語自体はデフォルトではどのデータベースにもインストールされません。 同様に、Perlサポート付きで構築した場合はPL/PerlPL/PerlUハンドラが、Pythonサポート付きで構築した場合はPL/PythonUハンドラが構築され、インストールされますが、言語自体はデフォルトではインストールされません。