CREATE OPERATOR <refpurpose>define a new operator</refpurpose> — 新しい演算子を定義する
CREATE OPERATORname
( {FUNCTION|PROCEDURE} =function_name
[, LEFTARG =left_type
] [, RIGHTARG =right_type
] [, COMMUTATOR =com_op
] [, NEGATOR =neg_op
] [, RESTRICT =res_proc
] [, JOIN =join_proc
] [, HASHES ] [, MERGES ] )
<command>CREATE OPERATOR</command> defines a new operator,
<replaceable class="parameter">name</replaceable>. The user who
defines an operator becomes its owner. If a schema name is given
then the operator is created in the specified schema. Otherwise it
is created in the current schema.
CREATE OPERATOR
は、新しい演算子name
を定義します。
演算子を定義したユーザがその所有者となります。
スキーマ名が指定されていた場合、その演算子は指定したスキーマに作成されます。
スキーマ名が指定されなかった場合、現在のスキーマに作成されます。
The operator name is a sequence of up to <symbol>NAMEDATALEN</symbol>-1
(63 by default) characters from the following list:
演算子名として使用できるのは、以下に示す文字を使った、NAMEDATALEN
-1(デフォルトでは63)文字までの文字列です。
+ - * / < > = ~ ! @ # % ^ & | ` ?
There are a few restrictions on your choice of name: 名前の選択には以下に示すいくつかの制約があります。
--
と/*
はコメントの開始とみなされてしまうため、演算子名の一部として使うことができません。
A multicharacter operator name cannot end in <literal>+</literal> or
<literal>-</literal>,
unless the name also contains at least one of these characters:
複数の文字からなる演算子名は、下記の文字のうちの1つ以上を含まない限り、+
または-
で終わることができません。
~ ! @ # % ^ & | ` ?
For example, <literal>@-</literal> is an allowed operator name,
but <literal>*-</literal> is not.
This restriction allows <productname>PostgreSQL</productname> to
parse SQL-compliant commands without requiring spaces between tokens.
例えば、@-
は演算子名として許されますが、*-
は許されません。
この制約により、PostgreSQLがSQLに準拠する問い合わせをトークン同士の間に空白を要求することなしに解析することが可能になります。
The use of <literal>=></literal> as an operator name is deprecated. It may
be disallowed altogether in a future release.
演算子名として=>
を使用することは廃止される予定です。
将来のリリースで完全に許されなくなるかもしれません。
The operator <literal>!=</literal> is mapped to
<literal><></literal> on input, so these two names are always
equivalent.
演算子!=
は入力時に<>
に変換されるので、これらの2つの名前は常に等価です。
For binary operators, both <literal>LEFTARG</literal> and
<literal>RIGHTARG</literal> must be defined. For prefix operators only
<literal>RIGHTARG</literal> should be defined.
二項演算子では、LEFTARG
とRIGHTARG
の両方を定義しなければなりません。
前置演算子ではRIGHTARG
のみを定義しなければなりません。
The <replaceable class="parameter">function_name</replaceable>
function must have been previously defined using <command>CREATE
FUNCTION</command> and must be defined to accept the correct number
of arguments (either one or two) of the indicated types.
function_name
関数は、CREATE FUNCTION
を使って事前に定義されていなければなりません。また、指定された型の正しい数の引数(1つか2つ)を受け付けるよう定義する必要があります。
In the syntax of <literal>CREATE OPERATOR</literal>, the keywords
<literal>FUNCTION</literal> and <literal>PROCEDURE</literal> are
equivalent, but the referenced function must in any case be a function, not
a procedure. The use of the keyword <literal>PROCEDURE</literal> here is
historical and deprecated.
CREATE OPERATOR
の構文では、キーワードFUNCTION
とPROCEDURE
は等価ですが、参照されている関数はどの場合も関数であって、プロシージャであってはなりません。
ここで、キーワードPROCEDURE
を使用することは歴史的なものであり、廃止予定です。
The other clauses specify optional operator optimization clauses. Their meaning is detailed in <xref linkend="xoper-optimization"/>. 他の句は演算子最適化用の句(省略可能)です。 これらの意味は38.15で説明されています。
To be able to create an operator, you must have <literal>USAGE</literal>
privilege on the argument types and the return type, as well
as <literal>EXECUTE</literal> privilege on the underlying function. If a
commutator or negator operator is specified, you must own these operators.
演算子を作成するためには、
引数の型と戻り値の型に対するUSAGE
権限と背後にある関数に対するEXECUTE
権限を持たなければなりません。
交代演算子または否定子演算子を指定する場合は、これらの演算子を所有していなければなりません。
name
The name of the operator to be defined. See above for allowable
characters. The name can be schema-qualified, for example
<literal>CREATE OPERATOR myschema.+ (...)</literal>. If not, then
the operator is created in the current schema. Two operators
in the same schema can have the same name if they operate on
different data types. This is called
<firstterm>overloading</firstterm>.
定義される演算子の名前です。
使用できる文字は上を参照してください。
この名前は、例えばCREATE OPERATOR myschema.+ (...)
のように、スキーマ修飾可能です。
修飾されていなければ、演算子は現在のスキーマに作成されます。
異なるデータ型について処理するものであれば、同じスキーマ内の2つの演算子は同じ名前を持つことができます。
これをオーバーロードと言います。
function_name
The function used to implement this operator. 演算子を実装するために使用する関数です。
left_type
The data type of the operator's left operand, if any. This option would be omitted for a prefix operator. 演算子の左オペランドのデータ型です(左オペランドが存在する場合のみ)。 このオプションは前置演算子では省略されます。
right_type
The data type of the operator's right operand. 演算子の右オペランドのデータ型です。
com_op
The commutator of this operator. この演算子の交代演算子です。
neg_op
The negator of this operator. この演算子の否定子です。
res_proc
The restriction selectivity estimator function for this operator. この演算子の制約選択評価関数です。
join_proc
The join selectivity estimator function for this operator. この演算子の結合選択評価関数です。
HASHES
Indicates this operator can support a hash join. この演算子がハッシュ結合をサポートできることを示します。
MERGES
Indicates this operator can support a merge join. この演算子がマージ結合をサポートできることを示します。
To give a schema-qualified operator name in <replaceable
class="parameter">com_op</replaceable> or the other optional
arguments, use the <literal>OPERATOR()</literal> syntax, for example:
スキーマ修飾された演算子名をcom_op
または他のオプション引数に与えるには、以下の例のようにOPERATOR()
構文を使用してください。
COMMUTATOR = OPERATOR(myschema.===) ,
Refer to <xref linkend="xoper"/> for further information. 詳細については38.14を参照してください。
It is not possible to specify an operator's lexical precedence in
<command>CREATE OPERATOR</command>, because the parser's precedence behavior
is hard-wired. See <xref linkend="sql-precedence"/> for precedence details.
CREATE OPERATOR
で演算子の語彙優先順位を指定することはできません。
パーサの優先順位に関する動作は固定であるためです。
詳細な優先順位については4.1.6を参照してください。
The obsolete options <literal>SORT1</literal>, <literal>SORT2</literal>,
<literal>LTCMP</literal>, and <literal>GTCMP</literal> were formerly used to
specify the names of sort operators associated with a merge-joinable
operator. This is no longer necessary, since information about
associated operators is found by looking at B-tree operator families
instead. If one of these options is given, it is ignored except
for implicitly setting <literal>MERGES</literal> true.
廃止されたオプションSORT1
、SORT2
、LTCMP
、およびGTCMP
は、マージ結合可能演算子に関連したソート演算子の名前を指定するために使用されていました。
代わりにB-tree演算子族を検索することで関連する演算子の情報を見つけることができるようになりましたので、これは必要がなくなりました。
これらの内のいずれかのオプションが指定された場合、暗黙的にMERGES
を真に設定するだけで、それ以外は無視します。
Use <link linkend="sql-dropoperator"><command>DROP OPERATOR</command></link> to delete user-defined operators
from a database. Use <link linkend="sql-alteroperator"><command>ALTER OPERATOR</command></link> to modify operators in a
database.
データベースからユーザ定義の演算子を削除するにはDROP OPERATOR
を使用してください。
データベース内の演算子を変更するにはALTER OPERATOR
を使用してください。
The following command defines a new operator, area-equality, for
the data type <type>box</type>:
以下のコマンドは、データ型box
に対する領域等価性を判定する新しい演算子を定義します。
CREATE OPERATOR === ( LEFTARG = box, RIGHTARG = box, FUNCTION = area_equal_function, COMMUTATOR = ===, NEGATOR = !==, RESTRICT = area_restriction_function, JOIN = area_join_function, HASHES, MERGES );
<command>CREATE OPERATOR</command> is a
<productname>PostgreSQL</productname> extension. There are no
provisions for user-defined operators in the SQL standard.
CREATE OPERATOR
はPostgreSQLの拡張です。
標準SQLには、ユーザ定義の演算子についての規定はありません。