2 $PostgreSQL: pgsql/doc/src/sgml/ref/alter_opfamily.sgml,v 1.7 2010/04/03 07:22:57 petere Exp $
3 PostgreSQL documentation
6 <refentry id="SQL-ALTEROPFAMILY">
8 <refentrytitle>ALTER OPERATOR FAMILY</refentrytitle>
9 <manvolnum>7</manvolnum>
10 <refmiscinfo>SQL - Language Statements</refmiscinfo>
14 <refname>ALTER OPERATOR FAMILY</refname>
15 <refpurpose>change the definition of an operator family</refpurpose>
18 <indexterm zone="sql-alteropfamily">
19 <primary>ALTER OPERATOR FAMILY</primary>
24 ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> ADD
25 { OPERATOR <replaceable class="parameter">strategy_number</replaceable> <replaceable class="parameter">operator_name</replaceable> ( <replaceable class="parameter">op_type</replaceable>, <replaceable class="parameter">op_type</replaceable> )
26 | FUNCTION <replaceable class="parameter">support_number</replaceable> [ ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] ) ] <replaceable class="parameter">function_name</replaceable> ( <replaceable class="parameter">argument_type</replaceable> [, ...] )
28 ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> DROP
29 { OPERATOR <replaceable class="parameter">strategy_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
30 | FUNCTION <replaceable class="parameter">support_number</replaceable> ( <replaceable class="parameter">op_type</replaceable> [ , <replaceable class="parameter">op_type</replaceable> ] )
32 ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> RENAME TO <replaceable>new_name</replaceable>
33 ALTER OPERATOR FAMILY <replaceable>name</replaceable> USING <replaceable class="parameter">index_method</replaceable> OWNER TO <replaceable>new_owner</replaceable>
38 <title>Description</title>
41 <command>ALTER OPERATOR FAMILY</command> changes the definition of
42 an operator family. You can add operators and support functions
43 to the family, remove them from the family,
44 or change the family's name or owner.
48 When operators and support functions are added to a family with
49 <command>ALTER OPERATOR FAMILY</command>, they are not part of any
50 specific operator class within the family, but are just <quote>loose</>
51 within the family. This indicates that these operators and functions
52 are compatible with the family's semantics, but are not required for
53 correct functioning of any specific index. (Operators and functions
54 that are so required should be declared as part of an operator class,
55 instead; see <xref linkend="sql-createopclass">.)
56 <productname>PostgreSQL</productname> will allow loose members of a
57 family to be dropped from the family at any time, but members of an
58 operator class cannot be dropped without dropping the whole class and
59 any indexes that depend on it.
60 Typically, single-data-type operators
61 and functions are part of operator classes because they are needed to
62 support an index on that specific data type, while cross-data-type
63 operators and functions are made loose members of the family.
67 You must be a superuser to use <command>ALTER OPERATOR FAMILY</>.
68 (This restriction is made because an erroneous operator family definition
69 could confuse or even crash the server.)
73 <command>ALTER OPERATOR FAMILY</command> does not presently check
74 whether the operator family definition includes all the operators and
75 functions required by the index method, nor whether the operators and
76 functions form a self-consistent set. It is the user's
77 responsibility to define a valid operator family.
81 Refer to <xref linkend="xindex"> for further information.
86 <title>Parameters</title>
90 <term><replaceable class="parameter">name</replaceable></term>
93 The name (optionally schema-qualified) of an existing operator
100 <term><replaceable class="parameter">index_method</replaceable></term>
103 The name of the index method this operator family is for.
109 <term><replaceable class="parameter">strategy_number</replaceable></term>
112 The index method's strategy number for an operator
113 associated with the operator family.
119 <term><replaceable class="parameter">operator_name</replaceable></term>
122 The name (optionally schema-qualified) of an operator associated
123 with the operator family.
129 <term><replaceable class="parameter">op_type</replaceable></term>
132 In an <literal>OPERATOR</> clause,
133 the operand data type(s) of the operator, or <literal>NONE</> to
134 signify a left-unary or right-unary operator. Unlike the comparable
135 syntax in <command>CREATE OPERATOR CLASS</>, the operand data types
136 must always be specified.
140 In an <literal>ADD FUNCTION</> clause, the operand data type(s) the
141 function is intended to support, if different from
142 the input data type(s) of the function. For B-tree and hash indexes
143 it is not necessary to specify <replaceable
144 class="parameter">op_type</replaceable> since the function's input
145 data type(s) are always the correct ones to use. For GIN and GiST
146 indexes it is necessary to specify the input data type the function
151 In a <literal>DROP FUNCTION</> clause, the operand data type(s) the
152 function is intended to support must be specified.
158 <term><replaceable class="parameter">support_number</replaceable></term>
161 The index method's support procedure number for a
162 function associated with the operator family.
168 <term><replaceable class="parameter">function_name</replaceable></term>
171 The name (optionally schema-qualified) of a function that is an
172 index method support procedure for the operator family.
178 <term><replaceable class="parameter">argument_type</replaceable></term>
181 The parameter data type(s) of the function.
187 <term><replaceable class="parameter">new_name</replaceable></term>
190 The new name of the operator family.
196 <term><replaceable class="parameter">new_owner</replaceable></term>
199 The new owner of the operator family.
206 The <literal>OPERATOR</> and <literal>FUNCTION</>
207 clauses can appear in any order.
216 Notice that the <literal>DROP</> syntax only specifies the <quote>slot</>
217 in the operator family, by strategy or support number and input data
218 type(s). The name of the operator or function occupying the slot is not
219 mentioned. Also, for <literal>DROP FUNCTION</> the type(s) to specify
220 are the input data type(s) the function is intended to support; for
221 GIN and GiST indexes this might have nothing to do with the actual input
222 argument types of the function.
226 Because the index machinery does not check access permissions on functions
227 before using them, including a function or operator in an operator family
228 is tantamount to granting public execute permission on it. This is usually
229 not an issue for the sorts of functions that are useful in an operator
234 The operators should not be defined by SQL functions. A SQL function
235 is likely to be inlined into the calling query, which will prevent
236 the optimizer from recognizing that the query matches an index.
240 Before <productname>PostgreSQL</productname> 8.4, the <literal>OPERATOR</>
241 clause could include a <literal>RECHECK</> option. This is no longer
242 supported because whether an index operator is <quote>lossy</> is now
243 determined on-the-fly at runtime. This allows efficient handling of
244 cases where an operator might or might not be lossy.
249 <title>Examples</title>
252 The following example command adds cross-data-type operators and
253 support functions to an operator family that already contains B-tree
254 operator classes for data types <type>int4</> and <type>int2</>.
258 ALTER OPERATOR FAMILY integer_ops USING btree ADD
261 OPERATOR 1 < (int4, int2) ,
262 OPERATOR 2 <= (int4, int2) ,
263 OPERATOR 3 = (int4, int2) ,
264 OPERATOR 4 >= (int4, int2) ,
265 OPERATOR 5 > (int4, int2) ,
266 FUNCTION 1 btint42cmp(int4, int2) ,
269 OPERATOR 1 < (int2, int4) ,
270 OPERATOR 2 <= (int2, int4) ,
271 OPERATOR 3 = (int2, int4) ,
272 OPERATOR 4 >= (int2, int4) ,
273 OPERATOR 5 > (int2, int4) ,
274 FUNCTION 1 btint24cmp(int2, int4) ;
278 To remove these entries again:
282 ALTER OPERATOR FAMILY integer_ops USING btree DROP
285 OPERATOR 1 (int4, int2) ,
286 OPERATOR 2 (int4, int2) ,
287 OPERATOR 3 (int4, int2) ,
288 OPERATOR 4 (int4, int2) ,
289 OPERATOR 5 (int4, int2) ,
290 FUNCTION 1 (int4, int2) ,
293 OPERATOR 1 (int2, int4) ,
294 OPERATOR 2 (int2, int4) ,
295 OPERATOR 3 (int2, int4) ,
296 OPERATOR 4 (int2, int4) ,
297 OPERATOR 5 (int2, int4) ,
298 FUNCTION 1 (int2, int4) ;
303 <title>Compatibility</title>
306 There is no <command>ALTER OPERATOR FAMILY</command> statement in
312 <title>See Also</title>
314 <simplelist type="inline">
315 <member><xref linkend="sql-createopfamily"></member>
316 <member><xref linkend="sql-dropopfamily"></member>
317 <member><xref linkend="sql-createopclass"></member>
318 <member><xref linkend="sql-alteropclass"></member>
319 <member><xref linkend="sql-dropopclass"></member>