CREATE LANGUAGE <refpurpose>define a new procedural language</refpurpose> — 新しい手続き言語を定義する
CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGEnameHANDLERcall_handler[ INLINEinline_handler] [ VALIDATORvalfunction] CREATE [ OR REPLACE ] [ TRUSTED ] [ PROCEDURAL ] LANGUAGEname
   <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は、言語名とその言語で作成された関数の実行に責任を持つハンドラ関数を関連付けます。
言語ハンドラについての詳細は、第57章を参照してください。
  
   <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と解釈されます。
言語が同じ名前の拡張としてパッケージ化されていれば問題なく動作するでしょう、そしてそのようなパッケージ化は手続き言語を設定するのによく行なわれている方法です。
  
TRUSTEDTRUSTEDは、他の方法ではユーザがアクセスできないデータに対しては、その言語でのアクセスが許されないことを指定します。
言語の登録時にこのキーワードを省略すると、PostgreSQLのスーパーユーザ権限を持つユーザのみが、この言語を使って新しい関数を作れるようになります。
      
PROCEDURALThis is a noise word. これには意味はありません。
nameThe name of the new procedural language. The name must be unique among the languages in the database. 新しい手続き言語の名前です。 この名前はデータベースの言語の中で一意でなければなりません。
HANDLER call_handlercall_handlerは手続き言語の関数を実行するために呼び出される関数の名前で、事前に登録しておく必要があります。
このハンドラは、Version-1呼び出し規約に則って、C言語のようなコンパイル言語で書かれている必要があります。また、引数を取らずlanguage_handler型を返す関数として、PostgreSQLに登録されていなければなりません。
language_handler型は、単に関数を呼び出しハンドラとして識別するのに使用するプレースホルダ型です。
      
INLINE inline_handlerinline_handlerはこの言語で無名コードブロックを実行(DOコマンド)するために呼び出される、事前に登録された関数の名前です。
inline_handler関数が指定されない場合、その言語では無名コードブロックをサポートしません。
このハンドラ関数は、DOコマンドの内部表現となるinternal型の引数を1つ取らなければならず、また、通常voidを返します。
ハンドラの戻り値は無視されます。
      
VALIDATOR valfunctionvalfunctionは、事前に登録された検証用関数の名前です。新しい関数が当該言語で作成された場合、その関数を検証するために呼び出されます。
検証用関数が指定されていない場合、新しい関数は作成時にチェックされません。
検証用関数は、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()関数を使用すべきです。
関数の戻り値は無視されます。
      
   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_language( 52.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データベースにインストールすることができます。
この場合、その後に作成されたすべてのデータベースで自動的にその言語は使用できるようになります。
  
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;
   <command>CREATE LANGUAGE</command> is a
   <productname>PostgreSQL</productname> extension.
CREATE LANGUAGEはPostgreSQLの拡張です。