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

CREATE LANGUAGE

CREATE LANGUAGE <refpurpose>define a new procedural language</refpurpose> — 新しい手続き言語を定義する

概要

CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name
    HANDLER call_handler [ INLINE inline_handler ] [ VALIDATOR valfunction ]
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGE name

説明

<title>Description</title>

<command>CREATE LANGUAGE</command> registers a new procedural language with a <productname>PostgreSQL</productname> database. Subsequently, functions and procedures can be defined in this new language. CREATE LANGUAGEは新しい手続き言語をPostgreSQLデータベースに登録します。 この後で、関数とプロシージャをその新しい言語で定義できるようになります。

<command>CREATE LANGUAGE</command> effectively associates the language name with handler function(s) that are responsible for executing functions written in the language. Refer to <xref linkend="plhandler"/> for more information about language handlers. CREATE LANGUAGEは、言語名とその言語で作成された関数の実行に責任を持つハンドラ関数を関連付けます。 言語ハンドラについての詳細は、第58章を参照してください。

<command>CREATE OR REPLACE LANGUAGE</command> will either create a new language, or replace an existing definition. If the language already exists, its parameters are updated according to the command, but the language's ownership and permissions settings do not change, and any existing functions written in the language are assumed to still be valid. CREATE OR REPLACE LANGUAGEは新しい言語を作成、または、既存の定義を置き換えます。 言語がすでに存在する場合、パラメータはコマンドに従って更新されますが、言語の所有権と権限に関する設定は変更されません。 また、その言語で作成された既存の関数も依然として有効であるものとみなされます。

One must have the <productname>PostgreSQL</productname> superuser privilege to register a new language or change an existing language's parameters. However, once the language is created it is valid to assign ownership of it to a non-superuser, who may then drop it, change its permissions, rename it, or assign it to a new owner. (Do not, however, assign ownership of the underlying C functions to a non-superuser; that would create a privilege escalation path for that user.) 新しい言語を登録する、または、既存の言語のパラメータを変更するには、ユーザはPostgreSQLのスーパーユーザ権限を持たなければなりません。 しかし、言語が一度作成されれば、その所有権を非スーパーユーザに割り当てたり、そのユーザが削除したり、権限を変更したり、新しい所有者に割り当てたりすることは有効です。 (しかしながら、基本的なC関数の所有権を非スーパーユーザに割り当てないでください。それは、そのユーザに権限昇格パスを作ることになるでしょう。)

The form of <command>CREATE LANGUAGE</command> that does not supply any handler function is obsolete. For backwards compatibility with old dump files, it is interpreted as <command>CREATE EXTENSION</command>. That will work if the language has been packaged into an extension of the same name, which is the conventional way to set up procedural languages. ハンドラ関数を指定しない形式のCREATE LANGUAGEは廃止されました。 古いダンプファイルとの後方互換性のため、CREATE EXTENSIONと解釈されます。 言語が同じ名前の拡張としてパッケージ化されていれば問題なく動作するでしょう、そしてそのようなパッケージ化は手続き言語を設定するのによく行なわれている方法です。

パラメータ

<title>Parameters</title>
TRUSTED
<para><literal>TRUSTED</literal> specifies that the language does not grant access to data that the user would not otherwise have. If this key word is omitted when registering the language, only users with the <productname>PostgreSQL</productname> superuser privilege can use this language to create new functions.

TRUSTEDは、他の方法ではユーザがアクセスできないデータに対しては、その言語でのアクセスが許されないことを指定します。 言語の登録時にこのキーワードを省略すると、PostgreSQLのスーパーユーザ権限を持つユーザのみが、この言語を使って新しい関数を作れるようになります。

PROCEDURAL

This is a noise word. これには意味はありません。

name

The name of the new procedural language. The name must be unique among the languages in the database. 新しい手続き言語の名前です。 この名前はデータベースの言語の中で一意でなければなりません。

HANDLER call_handler
<para><replaceable class="parameter">call_handler</replaceable> is the name of a previously registered function that will be called to execute the procedural language's 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 <productname>PostgreSQL</productname> as a function taking no arguments and returning the <type>language_handler</type> type, a placeholder type that is simply used to identify the function as a call handler.

call_handlerは手続き言語の関数を実行するために呼び出される関数の名前で、事前に登録しておく必要があります。 このハンドラは、Version-1呼び出し規約に則って、C言語のようなコンパイル言語で書かれている必要があります。また、引数を取らずlanguage_handler型を返す関数として、PostgreSQLに登録されていなければなりません。 language_handler型は、単に関数を呼び出しハンドラとして識別するのに使用するプレースホルダ型です。

INLINE inline_handler
<para><replaceable class="parameter">inline_handler</replaceable> is the name of a previously registered function that will be called to execute an anonymous code block (<link linkend="sql-do"><command>DO</command></link> command) in this language. If no <replaceable class="parameter">inline_handler</replaceable> function is specified, the language does not support anonymous code blocks. The handler function must take one argument of type <type>internal</type>, which will be the <command>DO</command> command's internal representation, and it will typically return <type>void</type>. The return value of the handler is ignored.

inline_handlerはこの言語で無名コードブロックを実行(DOコマンド)するために呼び出される、事前に登録された関数の名前です。 inline_handler関数が指定されない場合、その言語では無名コードブロックをサポートしません。 このハンドラ関数は、DOコマンドの内部表現となるinternal型の引数を1つ取らなければならず、また、通常voidを返します。 ハンドラの戻り値は無視されます。

VALIDATOR valfunction
<para><replaceable class="parameter">valfunction</replaceable> 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 <type>oid</type>, which will be the OID of the to-be-created function, and will typically return <type>void</type>.

valfunctionは、事前に登録された検証用関数の名前です。新しい関数が当該言語で作成された場合、その関数を検証するために呼び出されます。 検証用関数が指定されていない場合、新しい関数は作成時にチェックされません。 検証用関数は、oid型の引数を1つ取る必要があります。 この引数は作成される関数のOIDになります。 また、通常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 <function>ereport()</function> function. The return value of the function is ignored. 検証用関数は、通常、関数本体が構文上正しいかどうかを検査するために使用されます。 しかし、それだけでなく、関数のプロパティも検査可能です。例えば、その言語が処理できない特定のデータ型が引数に含まれていないかなどがチェックできます。 エラーを通知するには、検証用関数でereport()関数を使用すべきです。 関数の戻り値は無視されます。

注釈

<title>Notes</title>

Use <link linkend="sql-droplanguage"><command>DROP LANGUAGE</command></link> to drop procedural languages. 手続き言語を削除するにはDROP LANGUAGEを使用してください。

The system catalog <classname>pg_language</classname> (see <xref linkend="catalog-pg-language"/>) records information about the currently installed languages. Also, the <application>psql</application> command <command>\dL</command> lists the installed languages. システムカタログpg_language53.29参照)には、現在インストールされている言語に関する情報が記録されています。 またpsqlのコマンド\dLはインストールされた言語を一覧表示します。

To create functions in a procedural language, a user must have the <literal>USAGE</literal> privilege for the language. By default, <literal>USAGE</literal> is granted to <literal>PUBLIC</literal> (i.e., everyone) for trusted languages. This can be revoked if desired. 手続き言語で関数を作成するには、ユーザはその言語に対するUSAGE権限を持たなければなりません。 デフォルトでは、信頼された言語についてはPUBLICに(つまり全員に)USAGEが付与されています。 これは必要に応じて取り消すことができます。

Procedural languages are local to individual databases. However, a language can be installed into the <literal>template1</literal> database, which will cause it to be available automatically in all subsequently-created databases. 手続き言語は各データベースに局所的です。 しかし、言語をtemplate1データベースにインストールすることができます。 この場合、その後に作成されたすべてのデータベースで自動的にその言語は使用できるようになります。

<title>Examples</title>

A minimal sequence for creating a new procedural language is: 新しい手続き言語を作成する最小の手順は以下の通りです。

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

Typically that would be written in an extension's creation script, and users would do this to install the extension: 通常、これは拡張の作成スクリプト内に書かれており、ユーザは拡張をインストールすることでこれをすることになるでしょう。

CREATE EXTENSION plsample;

互換性

<title>Compatibility</title>

<command>CREATE LANGUAGE</command> is a <productname>PostgreSQL</productname> extension. CREATE LANGUAGEPostgreSQLの拡張です。

関連項目

<title>See Also</title> ALTER LANGUAGE, CREATE FUNCTION, DROP LANGUAGE, GRANT, REVOKE