CREATE OPERATOR CLASS 中文man頁面
NAME
CREATE OPERATOR CLASS - 定義一個新的操作符類
SYNOPSIS
CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS { OPERATOR strategy_number operator_name [ ( op_type, op_type ) ] [ RECHECK ] | FUNCTION support_number funcname ( argument_type [, ...] ) | STORAGE storage_type } [, ... ]
DESCRIPTION 描述
CREATE OPERATOR CLASS 定義一個新的操作符表。 一個操作符表定義一種特定的數(shù)據(jù)類型可以如何與一種索引一起使用。 操作符表聲明特定的操作符可以為這種數(shù)據(jù)類型以及這種索引方法填充特定角色或者"策略"。 操作符表還聲明索引方法在為一個索引字段選定該操作符表的時候要使用的支持過程。 所有操作符表使用的函數(shù)和操作符都必須在創(chuàng)建操作符表之前定義。
如果給出了模式名字,那么操作符表就在指定的模式中創(chuàng)建。 否則就在當前模式中創(chuàng)建(在搜索路徑前面的那個;參閱 CURRENT_SCHEMA())。 在同一個模式中的兩個操作符表可以有同樣的名字,但它們必須用于不同的索引方法。
定義操作符表的用戶成為其所有者。目前,創(chuàng)造者必須是超級用戶。 (作這樣的限制是因為一個有問題的操作符表定義會讓服務器困惑,甚至崩潰。)
CREATE OPERATOR CLASS 目前并不檢查這個類定義是否包含所有索引方法需要操作符以及函數(shù)。 定義一個合法的操作符表是用戶的責任。
參考 ``Interfacing Extensions to Indexes'' 獲取更多信息。
PARAMETERS 參數(shù)
- name
將要創(chuàng)建的操作符表的名字。名字可以用模式修飾。- DEFAULT
如果出現(xiàn)了這個鍵字,那么該操作符表將成為它的數(shù)據(jù)類型的缺省操作符表。 對于某個數(shù)據(jù)類型和訪問方式而言,最多可以有一個操作符表是缺省的。- data_type
這個操作符表處理的字段數(shù)據(jù)類型。- index_method
這個操作符表處理的索引訪問方式的名字。- strategy_number
一個操作符和這個操作符表關(guān)聯(lián)的索引訪問方式的策略數(shù)。- operator_name
一個和該操作符表關(guān)聯(lián)的操作符的名字(可以用模式修飾)。- op_type
一個操作符的輸入數(shù)據(jù)類型,或者是 NONE 表示左目或者右目操作符。 通常情況下可以省略輸入數(shù)據(jù)類型,因為這個時候它們和操作符表的數(shù)據(jù)類型相同。- RECHECK
如果出現(xiàn),那么索引對這個操作符是"lossy"(有損耗的), 因此,使用這個索引檢索的行必須重新檢查,以保證它們真正滿足和此操作符相關(guān)的條件子句。- support_number
索引方法對一個與操作符表關(guān)聯(lián)的函數(shù)的支持過程數(shù)。- funcname
一個函數(shù)的名字(可以有模式修飾),這個函數(shù)是索引訪問方式對此操作符表的支持過程。- argument_types
函數(shù)的參數(shù)數(shù)據(jù)類型。- storage_type
實際存儲在索引里的數(shù)據(jù)類型。通常它和字段數(shù)據(jù)類型相同, 但是一些索引方法(到目前為止只有 GIST)允許它是不同的。 除非索引方法允許使用一種不同的類型,否則必須省略 STORAGE 子句。
OPERATOR,F(xiàn)UNCTION,和 STORAGE 子句可以按照任意順序出現(xiàn)。
EXAMPLES 例子
下面的例子命令為數(shù)據(jù)類型 _int4(int4 的數(shù)組)定義了一個 GiST 索引操作符表。 參閱 contrib/intarray/ 獲取完整的例子。
CREATE OPERATOR CLASS gist__int_ops DEFAULT FOR TYPE _int4 USING gist AS OPERATOR 3 &&, OPERATOR 6 = RECHECK, OPERATOR 7 @, OPERATOR 8 ~, OPERATOR 20 @@ (_int4, query_int), FUNCTION 1 g_int_consistent (internal, _int4, int4), FUNCTION 2 g_int_union (bytea, internal), FUNCTION 3 g_int_compress (internal), FUNCTION 4 g_int_decompress (internal), FUNCTION 5 g_int_penalty (internal, internal, internal), FUNCTION 6 g_int_picksplit (internal, internal), FUNCTION 7 g_int_same (_int4, _int4, internal);
COMPATIBILITY 兼容性
CREATE OPERATOR CLASS 是一個 PostgreSQL 擴展。 在 SQL 標準中沒有 CREATE OPERATOR CLASS。
SEE ALSO 參見
ALTER OPERATOR CLASS [alter_operator_class(7)], DROP OPERATOR CLASS [drop_operator_class(l)]
#p#
NAME
CREATE OPERATOR CLASS - define a new operator class
SYNOPSIS
CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS { OPERATOR strategy_number operator_name [ ( op_type, op_type ) ] [ RECHECK ] | FUNCTION support_number funcname ( argument_type [, ...] ) | STORAGE storage_type } [, ... ]
DESCRIPTION
CREATE OPERATOR CLASS creates a new operator class. An operator class defines how a particular data type can be used with an index. The operator class specifies that certain operators will fill particular roles or ``strategies'' for this data type and this index method. The operator class also specifies the support procedures to be used by the index method when the operator class is selected for an index column. All the operators and functions used by an operator class must be defined before the operator class is created.
If a schema name is given then the operator class is created in the specified schema. Otherwise it is created in the current schema. Two operator classes in the same schema can have the same name only if they are for different index methods.
The user who defines an operator class becomes its owner. Presently, the creating user must be a superuser. (This restriction is made because an erroneous operator class definition could confuse or even crash the server.)
CREATE OPERATOR CLASS does not presently check whether the operator class definition includes all the operators and functions required by the index method. It is the user's responsibility to define a valid operator class.
Refer to the section called ``Interfacing Extensions to Indexes'' in the documentation for further information.
PARAMETERS
- name
- The name of the operator class to be created. The name may be schema-qualified.
- DEFAULT
- If present, the operator class will become the default operator class for its data type. At most one operator class can be the default for a specific data type and index method.
- data_type
- The column data type that this operator class is for.
- index_method
- The name of the index method this operator class is for.
- strategy_number
- The index method's strategy number for an operator associated with the operator class.
- operator_name
- The name (optionally schema-qualified) of an operator associated with the operator class.
- op_type
- The operand data type(s) of an operator, or NONE to signify a left-unary or right-unary operator. The operand data types may be omitted in the normal case where they are the same as the operator class's data type.
- RECHECK
- If present, the index is ``lossy'' for this operator, and so the rows retrieved using the index must be rechecked to verify that they actually satisfy the qualification clause involving this operator.
- support_number
- The index method's support procedure number for a function associated with the operator class.
- funcname
- The name (optionally schema-qualified) of a function that is an index method support procedure for the operator class.
- argument_types
- The parameter data type(s) of the function.
- storage_type
- The data type actually stored in the index. Normally this is the same as the column data type, but some index methods (only GiST at this writing) allow it to be different. The STORAGE clause must be omitted unless the index method allows a different type to be used.
The OPERATOR, FUNCTION, and STORAGE clauses may appear in any order.
EXAMPLES
The following example command defines a GiST index operator class for the data type _int4 (array of int4). See contrib/intarray/ for the complete example.
CREATE OPERATOR CLASS gist__int_ops DEFAULT FOR TYPE _int4 USING gist AS OPERATOR 3 &&, OPERATOR 6 = RECHECK, OPERATOR 7 @, OPERATOR 8 ~, OPERATOR 20 @@ (_int4, query_int), FUNCTION 1 g_int_consistent (internal, _int4, int4), FUNCTION 2 g_int_union (bytea, internal), FUNCTION 3 g_int_compress (internal), FUNCTION 4 g_int_decompress (internal), FUNCTION 5 g_int_penalty (internal, internal, internal), FUNCTION 6 g_int_picksplit (internal, internal), FUNCTION 7 g_int_same (_int4, _int4, internal);
COMPATIBILITY
CREATE OPERATOR CLASS is a PostgreSQL extension. There is no CREATE OPERATOR CLASS statement in the SQL standard.
SEE ALSO
ALTER OPERATOR CLASS [alter_operator_class(7)], DROP OPERATOR CLASS [drop_operator_class(l)]