1CREATE OPERATOR CLASS(7) PostgreSQL 10.7 DocumentationCREATE OPERATOR CLASS(7)
2
3
4

NAME

6       CREATE_OPERATOR_CLASS - define a new operator class
7

SYNOPSIS

9       CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type
10         USING index_method [ FAMILY family_name ] AS
11         {  OPERATOR strategy_number operator_name [ ( op_type, op_type ) ] [ FOR SEARCH | FOR ORDER BY sort_family_name ]
12          | FUNCTION support_number [ ( op_type [ , op_type ] ) ] function_name ( argument_type [, ...] )
13          | STORAGE storage_type
14         } [, ... ]
15

DESCRIPTION

17       CREATE OPERATOR CLASS creates a new operator class. An operator class
18       defines how a particular data type can be used with an index. The
19       operator class specifies that certain operators will fill particular
20       roles or “strategies” for this data type and this index method. The
21       operator class also specifies the support procedures to be used by the
22       index method when the operator class is selected for an index column.
23       All the operators and functions used by an operator class must be
24       defined before the operator class can be created.
25
26       If a schema name is given then the operator class is created in the
27       specified schema. Otherwise it is created in the current schema. Two
28       operator classes in the same schema can have the same name only if they
29       are for different index methods.
30
31       The user who defines an operator class becomes its owner. Presently,
32       the creating user must be a superuser. (This restriction is made
33       because an erroneous operator class definition could confuse or even
34       crash the server.)
35
36       CREATE OPERATOR CLASS does not presently check whether the operator
37       class definition includes all the operators and functions required by
38       the index method, nor whether the operators and functions form a
39       self-consistent set. It is the user's responsibility to define a valid
40       operator class.
41
42       Related operator classes can be grouped into operator families. To add
43       a new operator class to an existing family, specify the FAMILY option
44       in CREATE OPERATOR CLASS. Without this option, the new class is placed
45       into a family named the same as the new class (creating that family if
46       it doesn't already exist).
47
48       Refer to Section 37.14 for further information.
49

PARAMETERS

51       name
52           The name of the operator class to be created. The name can be
53           schema-qualified.
54
55       DEFAULT
56           If present, the operator class will become the default operator
57           class for its data type. At most one operator class can be the
58           default for a specific data type and index method.
59
60       data_type
61           The column data type that this operator class is for.
62
63       index_method
64           The name of the index method this operator class is for.
65
66       family_name
67           The name of the existing operator family to add this operator class
68           to. If not specified, a family named the same as the operator class
69           is used (creating it, if it doesn't already exist).
70
71       strategy_number
72           The index method's strategy number for an operator associated with
73           the operator class.
74
75       operator_name
76           The name (optionally schema-qualified) of an operator associated
77           with the operator class.
78
79       op_type
80           In an OPERATOR clause, the operand data type(s) of the operator, or
81           NONE to signify a left-unary or right-unary operator. The operand
82           data types can be omitted in the normal case where they are the
83           same as the operator class's data type.
84
85           In a FUNCTION clause, the operand data type(s) the function is
86           intended to support, if different from the input data type(s) of
87           the function (for B-tree comparison functions and hash functions)
88           or the class's data type (for B-tree sort support functions and all
89           functions in GiST, SP-GiST, GIN and BRIN operator classes). These
90           defaults are correct, and so op_type need not be specified in
91           FUNCTION clauses, except for the case of a B-tree sort support
92           function that is meant to support cross-data-type comparisons.
93
94       sort_family_name
95           The name (optionally schema-qualified) of an existing btree
96           operator family that describes the sort ordering associated with an
97           ordering operator.
98
99           If neither FOR SEARCH nor FOR ORDER BY is specified, FOR SEARCH is
100           the default.
101
102       support_number
103           The index method's support procedure number for a function
104           associated with the operator class.
105
106       function_name
107           The name (optionally schema-qualified) of a function that is an
108           index method support procedure for the operator class.
109
110       argument_type
111           The parameter data type(s) of the function.
112
113       storage_type
114           The data type actually stored in the index. Normally this is the
115           same as the column data type, but some index methods (currently
116           GiST, GIN and BRIN) allow it to be different. The STORAGE clause
117           must be omitted unless the index method allows a different type to
118           be used. If the column data_type is specified as anyarray, the
119           storage_type can be declared as anyelement to indicate that the
120           index entries are members of the element type belonging to the
121           actual array type that each particular index is created for.
122
123       The OPERATOR, FUNCTION, and STORAGE clauses can appear in any order.
124

NOTES

126       Because the index machinery does not check access permissions on
127       functions before using them, including a function or operator in an
128       operator class is tantamount to granting public execute permission on
129       it. This is usually not an issue for the sorts of functions that are
130       useful in an operator class.
131
132       The operators should not be defined by SQL functions. A SQL function is
133       likely to be inlined into the calling query, which will prevent the
134       optimizer from recognizing that the query matches an index.
135
136       Before PostgreSQL 8.4, the OPERATOR clause could include a RECHECK
137       option. This is no longer supported because whether an index operator
138       is “lossy” is now determined on-the-fly at run time. This allows
139       efficient handling of cases where an operator might or might not be
140       lossy.
141

EXAMPLES

143       The following example command defines a GiST index operator class for
144       the data type _int4 (array of int4). See the intarray module for the
145       complete example.
146
147           CREATE OPERATOR CLASS gist__int_ops
148               DEFAULT FOR TYPE _int4 USING gist AS
149                   OPERATOR        3       &&,
150                   OPERATOR        6       = (anyarray, anyarray),
151                   OPERATOR        7       @>,
152                   OPERATOR        8       <@,
153                   OPERATOR        20      @@ (_int4, query_int),
154                   FUNCTION        1       g_int_consistent (internal, _int4, smallint, oid, internal),
155                   FUNCTION        2       g_int_union (internal, internal),
156                   FUNCTION        3       g_int_compress (internal),
157                   FUNCTION        4       g_int_decompress (internal),
158                   FUNCTION        5       g_int_penalty (internal, internal, internal),
159                   FUNCTION        6       g_int_picksplit (internal, internal),
160                   FUNCTION        7       g_int_same (_int4, _int4, internal);
161

COMPATIBILITY

163       CREATE OPERATOR CLASS is a PostgreSQL extension. There is no CREATE
164       OPERATOR CLASS statement in the SQL standard.
165

SEE ALSO

167       ALTER OPERATOR CLASS (ALTER_OPERATOR_CLASS(7)), DROP OPERATOR CLASS
168       (DROP_OPERATOR_CLASS(7)), CREATE OPERATOR FAMILY
169       (CREATE_OPERATOR_FAMILY(7)), ALTER OPERATOR FAMILY
170       (ALTER_OPERATOR_FAMILY(7))
171
172
173
174PostgreSQL 10.7                      2019             CREATE OPERATOR CLASS(7)
Impressum