1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>CREATE OPERATOR CLASS</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
<link rev="made" href="pgsql-docs@postgresql.org">
<meta name="generator" content="DocBook XSL Stylesheets V1.70.0">
<link rel="start" href="index.html" title="PostgreSQL 8.1.4 Documentation">
<link rel="up" href="sql-commands.html" title="SQL Commands">
<link rel="prev" href="sql-createoperator.html" title="CREATE OPERATOR">
<link rel="next" href="sql-createrole.html" title="CREATE ROLE">
<link rel="copyright" href="ln-legalnotice.html" title="Legal Notice">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="refentry" lang="en">
<a name="sql-createopclass"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>CREATE OPERATOR CLASS — define a new operator class</p>
</div>
<a name="id758478"></a><div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">CREATE OPERATOR CLASS <em class="replaceable"><code>name</code></em> [ DEFAULT ] FOR TYPE <em class="replaceable"><code>data_type</code></em> USING <em class="replaceable"><code>index_method</code></em> AS
{ OPERATOR <em class="replaceable"><code>strategy_number</code></em> <em class="replaceable"><code>operator_name</code></em> [ ( <em class="replaceable"><code>op_type</code></em>, <em class="replaceable"><code>op_type</code></em> ) ] [ RECHECK ]
| FUNCTION <em class="replaceable"><code>support_number</code></em> <em class="replaceable"><code>funcname</code></em> ( <em class="replaceable"><code>argument_type</code></em> [, ...] )
| STORAGE <em class="replaceable"><code>storage_type</code></em>
} [, ... ]</pre>
</div>
<div class="refsect1" lang="en">
<a name="id758570"></a><h2>Description</h2>
<p> <code class="command">CREATE OPERATOR CLASS</code> 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 “<span class="quote">strategies</span>” 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.
</p>
<p> 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.
</p>
<p> 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.)
</p>
<p> <code class="command">CREATE OPERATOR CLASS</code> 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.
</p>
<p> Refer to <a href="xindex.html" title="32.14.Interfacing Extensions To Indexes">Section32.14, “Interfacing Extensions To Indexes”</a> for further information.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id758632"></a><h2>Parameters</h2>
<div class="variablelist"><dl>
<dt><span class="term"><em class="replaceable"><code>name</code></em></span></dt>
<dd><p> The name of the operator class to be created. The name may be
schema-qualified.
</p></dd>
<dt><span class="term"><code class="literal">DEFAULT</code></span></dt>
<dd><p> 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.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>data_type</code></em></span></dt>
<dd><p> The column data type that this operator class is for.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>index_method</code></em></span></dt>
<dd><p> The name of the index method this operator class is for.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>strategy_number</code></em></span></dt>
<dd><p> The index method's strategy number for an operator
associated with the operator class.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>operator_name</code></em></span></dt>
<dd><p> The name (optionally schema-qualified) of an operator associated
with the operator class.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>op_type</code></em></span></dt>
<dd><p> The operand data type(s) of an operator, or <code class="literal">NONE</code> 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.
</p></dd>
<dt><span class="term"><code class="literal">RECHECK</code></span></dt>
<dd><p> If present, the index is “<span class="quote">lossy</span>” 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.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>support_number</code></em></span></dt>
<dd><p> The index method's support procedure number for a
function associated with the operator class.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>funcname</code></em></span></dt>
<dd><p> The name (optionally schema-qualified) of a function that is an
index method support procedure for the operator class.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>argument_types</code></em></span></dt>
<dd><p> The parameter data type(s) of the function.
</p></dd>
<dt><span class="term"><em class="replaceable"><code>storage_type</code></em></span></dt>
<dd><p> 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
<code class="literal">STORAGE</code> clause must be omitted unless the index
method allows a different type to be used.
</p></dd>
</dl></div>
<p> The <code class="literal">OPERATOR</code>, <code class="literal">FUNCTION</code>, and <code class="literal">STORAGE</code>
clauses may appear in any order.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id758843"></a><h2>Notes</h2>
<p> The operators should not be defined by SQL functions. A SQL function
is likely to be inlined into the calling query, which will prevent
the optimizer from recognizing that the query matches an index.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id758853"></a><h2>Examples</h2>
<p> The following example command defines a GiST index operator class
for the data type <code class="literal">_int4</code> (array of <code class="type">int4</code>). See
<code class="filename">contrib/intarray/</code> for the complete example.
</p>
<pre class="programlisting">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);</pre>
</div>
<div class="refsect1" lang="en">
<a name="id758913"></a><h2>Compatibility</h2>
<p> <code class="command">CREATE OPERATOR CLASS</code> is a
<span class="productname">PostgreSQL</span> extension. There is no
<code class="command">CREATE OPERATOR CLASS</code> statement in the SQL
standard.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id758941"></a><h2>See Also</h2>
<span class="simplelist"><a href="sql-alteropclass.html">ALTER OPERATOR CLASS</a>, <a href="sql-dropopclass.html">DROP OPERATOR CLASS</a></span>
</div>
</div></body>
</html>
|