1CREATE OPERATOR CLASS()          SQL Commands          CREATE OPERATOR CLASS()
2
3
4

NAME

6       CREATE OPERATOR CLASS - define a new operator class
7
8

SYNOPSIS

10       CREATE OPERATOR CLASS name [ DEFAULT ] FOR TYPE data_type USING index_method AS
11         {  OPERATOR strategy_number operator_name [ ( op_type, op_type ) ] [ RECHECK ]
12          | FUNCTION support_number funcname ( argument_type [, ...] )
13          | STORAGE storage_type
14         } [, ... ]
15
16

DESCRIPTION

18       CREATE  OPERATOR CLASS creates a new operator class.  An operator class
19       defines how a particular data type can be used with an index. The oper‐
20       ator  class specifies that certain operators will fill particular roles
21       or ``strategies'' for this data type and this index method. The  opera‐
22       tor class also specifies the support procedures to be used by the index
23       method when the operator class is selected for an index column. All the
24       operators  and  functions  used  by  an  operator class must be defined
25       before the operator class is created.
26
27       If a schema name is given then the operator class  is  created  in  the
28       specified  schema.  Otherwise it is created in the current schema.  Two
29       operator classes in the same schema can have the same name only if they
30       are for different index methods.
31
32       The  user  who  defines an operator class becomes its owner. Presently,
33       the creating user must  be  a  superuser.  (This  restriction  is  made
34       because  an  erroneous  operator class definition could confuse or even
35       crash the server.)
36
37       CREATE OPERATOR CLASS does not presently  check  whether  the  operator
38       class  definition  includes all the operators and functions required by
39       the index method, nor whether the operators and functions form a  self-
40       consistent set. It is the user's responsibility to define a valid oper‐
41       ator class.
42
43       Refer to in the documentation for further information.
44

PARAMETERS

46       name   The name of the operator class to be created. The  name  may  be
47              schema-qualified.
48
49       DEFAULT
50              If  present, the operator class will become the default operator
51              class for its data type. At most one operator class can  be  the
52              default for a specific data type and index method.
53
54       data_type
55              The column data type that this operator class is for.
56
57       index_method
58              The name of the index method this operator class is for.
59
60       strategy_number
61              The  index  method's  strategy number for an operator associated
62              with the operator class.
63
64       operator_name
65              The name (optionally schema-qualified) of an operator associated
66              with the operator class.
67
68       op_type
69              The  operand  data  type(s) of an operator, or NONE to signify a
70              left-unary or right-unary operator. The operand data  types  may
71              be  omitted  in  the  normal case where they are the same as the
72              operator class's data type.
73
74       RECHECK
75              If present, the index is ``lossy'' for this operator, and so the
76              rows  retrieved using the index must be rechecked to verify that
77              they actually satisfy the qualification  clause  involving  this
78              operator.
79
80       support_number
81              The index method's support procedure number for a function asso‐
82              ciated with the operator class.
83
84       funcname
85              The name (optionally schema-qualified) of a function that is  an
86              index method support procedure for the operator class.
87
88       argument_types
89              The parameter data type(s) of the function.
90
91       storage_type
92              The data type actually stored in the index. Normally this is the
93              same as the column data type, but some index  methods  (GIN  and
94              GiST  for now) allow it to be different. The STORAGE clause must
95              be omitted unless the index method allows a different type to be
96              used.
97
98       The OPERATOR, FUNCTION, and STORAGE clauses may appear in any order.
99

NOTES

101       Because  the index machinery does not check access permissions on func‐
102       tions before using them, including a function or operator in an  opera‐
103       tor  class  is  tantamount to granting public execute permission on it.
104       This is usually not an issue for the sorts of functions that are useful
105       in an operator class.
106
107       The operators should not be defined by SQL functions. A SQL function is
108       likely to be inlined into the calling query,  which  will  prevent  the
109       optimizer from recognizing that the query matches an index.
110

EXAMPLES

112       The  following  example command defines a GiST index operator class for
113       the data type _int4 (array of int4). See contrib/intarray/ for the com‐
114       plete example.
115
116       CREATE OPERATOR CLASS gist__int_ops
117           DEFAULT FOR TYPE _int4 USING gist AS
118               OPERATOR        3       &&,
119               OPERATOR        6       =       RECHECK,
120               OPERATOR        7       @>,
121               OPERATOR        8       <@,
122               OPERATOR        20      @@ (_int4, query_int),
123               FUNCTION        1       g_int_consistent (internal, _int4, int4),
124               FUNCTION        2       g_int_union (bytea, internal),
125               FUNCTION        3       g_int_compress (internal),
126               FUNCTION        4       g_int_decompress (internal),
127               FUNCTION        5       g_int_penalty (internal, internal, internal),
128               FUNCTION        6       g_int_picksplit (internal, internal),
129               FUNCTION        7       g_int_same (_int4, _int4, internal);
130
131

COMPATIBILITY

133       CREATE  OPERATOR  CLASS  is  a PostgreSQL extension. There is no CREATE
134       OPERATOR CLASS statement in the SQL standard.
135

SEE ALSO

137       ALTER OPERATOR CLASS  [alter_operator_class(7)],  DROP  OPERATOR  CLASS
138       [drop_operator_class(l)]
139
140
141
142SQL - Language Statements         2008-06-08           CREATE OPERATOR CLASS()
Impressum