1CREATE OPERATOR CLASS(7)PostgreSQL 9.2.24 DocumentationCREATE OPERATOR CLASS(7)
2
3
4
6 CREATE_OPERATOR_CLASS - define a new operator class
7
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
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 35.14, “Interfacing Extensions To Indexes”, in the
49 documentation for further information.
50
52 name
53 The name of the operator class to be created. The name can be
54 schema-qualified.
55
56 DEFAULT
57 If present, the operator class will become the default operator
58 class for its data type. At most one operator class can be the
59 default for a specific data type and index method.
60
61 data_type
62 The column data type that this operator class is for.
63
64 index_method
65 The name of the index method this operator class is for.
66
67 family_name
68 The name of the existing operator family to add this operator class
69 to. If not specified, a family named the same as the operator class
70 is used (creating it, if it doesn't already exist).
71
72 strategy_number
73 The index method's strategy number for an operator associated with
74 the operator class.
75
76 operator_name
77 The name (optionally schema-qualified) of an operator associated
78 with the operator class.
79
80 op_type
81 In an OPERATOR clause, the operand data type(s) of the operator, or
82 NONE to signify a left-unary or right-unary operator. The operand
83 data types can be omitted in the normal case where they are the
84 same as the operator class's data type.
85
86 In a FUNCTION clause, the operand data type(s) the function is
87 intended to support, if different from the input data type(s) of
88 the function (for B-tree comparison functions and hash functions)
89 or the class's data type (for B-tree sort support functions and all
90 functions in GiST, SP-GiST and GIN operator classes). These
91 defaults are correct, and so op_type need not be specified in
92 FUNCTION clauses, except for the case of a B-tree sort support
93 function that is meant to support cross-data-type comparisons.
94
95 sort_family_name
96 The name (optionally schema-qualified) of an existing btree
97 operator family that describes the sort ordering associated with an
98 ordering operator.
99
100 If neither FOR SEARCH nor FOR ORDER BY is specified, FOR SEARCH is
101 the default.
102
103 support_number
104 The index method's support procedure number for a function
105 associated with the operator class.
106
107 function_name
108 The name (optionally schema-qualified) of a function that is an
109 index method support procedure for the operator class.
110
111 argument_type
112 The parameter data type(s) of the function.
113
114 storage_type
115 The data type actually stored in the index. Normally this is the
116 same as the column data type, but some index methods (currently
117 GiST and GIN) allow it to be different. The STORAGE clause must be
118 omitted unless the index method allows a different type to be used.
119
120 The OPERATOR, FUNCTION, and STORAGE clauses can appear in any order.
121
123 Because the index machinery does not check access permissions on
124 functions before using them, including a function or operator in an
125 operator class is tantamount to granting public execute permission on
126 it. This is usually not an issue for the sorts of functions that are
127 useful in an operator class.
128
129 The operators should not be defined by SQL functions. A SQL function is
130 likely to be inlined into the calling query, which will prevent the
131 optimizer from recognizing that the query matches an index.
132
133 Before PostgreSQL 8.4, the OPERATOR clause could include a RECHECK
134 option. This is no longer supported because whether an index operator
135 is “lossy” is now determined on-the-fly at run time. This allows
136 efficient handling of cases where an operator might or might not be
137 lossy.
138
140 The following example command defines a GiST index operator class for
141 the data type _int4 (array of int4). See the intarray module for the
142 complete example.
143
144 CREATE OPERATOR CLASS gist__int_ops
145 DEFAULT FOR TYPE _int4 USING gist AS
146 OPERATOR 3 &&,
147 OPERATOR 6 = (anyarray, anyarray),
148 OPERATOR 7 @>,
149 OPERATOR 8 <@,
150 OPERATOR 20 @@ (_int4, query_int),
151 FUNCTION 1 g_int_consistent (internal, _int4, int, oid, internal),
152 FUNCTION 2 g_int_union (internal, internal),
153 FUNCTION 3 g_int_compress (internal),
154 FUNCTION 4 g_int_decompress (internal),
155 FUNCTION 5 g_int_penalty (internal, internal, internal),
156 FUNCTION 6 g_int_picksplit (internal, internal),
157 FUNCTION 7 g_int_same (_int4, _int4, internal);
158
160 CREATE OPERATOR CLASS is a PostgreSQL extension. There is no CREATE
161 OPERATOR CLASS statement in the SQL standard.
162
164 ALTER OPERATOR CLASS (ALTER_OPERATOR_CLASS(7)), DROP OPERATOR CLASS
165 (DROP_OPERATOR_CLASS(7)), CREATE OPERATOR FAMILY
166 (CREATE_OPERATOR_FAMILY(7)), ALTER OPERATOR FAMILY
167 (ALTER_OPERATOR_FAMILY(7))
168
169
170
171PostgreSQL 9.2.24 2017-11-06 CREATE OPERATOR CLASS(7)