]> begriffs open source - ai-pg/blob - full-docs/man7/ALTER_OPERATOR_FAMILY.7
Include links to all subsection html pages, with shorter paths too
[ai-pg] / full-docs / man7 / ALTER_OPERATOR_FAMILY.7
1 '\" t
2 .\"     Title: ALTER OPERATOR FAMILY
3 .\"    Author: The PostgreSQL Global Development Group
4 .\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
5 .\"      Date: 2025
6 .\"    Manual: PostgreSQL 18.0 Documentation
7 .\"    Source: PostgreSQL 18.0
8 .\"  Language: English
9 .\"
10 .TH "ALTER OPERATOR FAMILY" "7" "2025" "PostgreSQL 18.0" "PostgreSQL 18.0 Documentation"
11 .\" -----------------------------------------------------------------
12 .\" * Define some portability stuff
13 .\" -----------------------------------------------------------------
14 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15 .\" http://bugs.debian.org/507673
16 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
17 .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18 .ie \n(.g .ds Aq \(aq
19 .el       .ds Aq '
20 .\" -----------------------------------------------------------------
21 .\" * set default formatting
22 .\" -----------------------------------------------------------------
23 .\" disable hyphenation
24 .nh
25 .\" disable justification (adjust text to left margin only)
26 .ad l
27 .\" -----------------------------------------------------------------
28 .\" * MAIN CONTENT STARTS HERE *
29 .\" -----------------------------------------------------------------
30 .SH "NAME"
31 ALTER_OPERATOR_FAMILY \- change the definition of an operator family
32 .SH "SYNOPSIS"
33 .sp
34 .nf
35 ALTER OPERATOR FAMILY \fIname\fR USING \fIindex_method\fR ADD
36   {  OPERATOR \fIstrategy_number\fR \fIoperator_name\fR ( \fIop_type\fR, \fIop_type\fR )
37               [ FOR SEARCH | FOR ORDER BY \fIsort_family_name\fR ]
38    | FUNCTION \fIsupport_number\fR [ ( \fIop_type\fR [ , \fIop_type\fR ] ) ]
39               \fIfunction_name\fR [ ( \fIargument_type\fR [, \&.\&.\&.] ) ]
40   } [, \&.\&.\&. ]
41
42 ALTER OPERATOR FAMILY \fIname\fR USING \fIindex_method\fR DROP
43   {  OPERATOR \fIstrategy_number\fR ( \fIop_type\fR [ , \fIop_type\fR ] )
44    | FUNCTION \fIsupport_number\fR ( \fIop_type\fR [ , \fIop_type\fR ] )
45   } [, \&.\&.\&. ]
46
47 ALTER OPERATOR FAMILY \fIname\fR USING \fIindex_method\fR
48     RENAME TO \fInew_name\fR
49
50 ALTER OPERATOR FAMILY \fIname\fR USING \fIindex_method\fR
51     OWNER TO { \fInew_owner\fR | CURRENT_ROLE | CURRENT_USER | SESSION_USER }
52
53 ALTER OPERATOR FAMILY \fIname\fR USING \fIindex_method\fR
54     SET SCHEMA \fInew_schema\fR
55 .fi
56 .SH "DESCRIPTION"
57 .PP
58 \fBALTER OPERATOR FAMILY\fR
59 changes the definition of an operator family\&. You can add operators and support functions to the family, remove them from the family, or change the family\*(Aqs name or owner\&.
60 .PP
61 When operators and support functions are added to a family with
62 \fBALTER OPERATOR FAMILY\fR, they are not part of any specific operator class within the family, but are just
63 \(lqloose\(rq
64 within the family\&. This indicates that these operators and functions are compatible with the family\*(Aqs semantics, but are not required for correct functioning of any specific index\&. (Operators and functions that are so required should be declared as part of an operator class, instead; see
65 CREATE OPERATOR CLASS (\fBCREATE_OPERATOR_CLASS\fR(7))\&.)
66 PostgreSQL
67 will allow loose members of a family to be dropped from the family at any time, but members of an operator class cannot be dropped without dropping the whole class and any indexes that depend on it\&. Typically, single\-data\-type operators and functions are part of operator classes because they are needed to support an index on that specific data type, while cross\-data\-type operators and functions are made loose members of the family\&.
68 .PP
69 You must be a superuser to use
70 \fBALTER OPERATOR FAMILY\fR\&. (This restriction is made because an erroneous operator family definition could confuse or even crash the server\&.)
71 .PP
72 \fBALTER OPERATOR FAMILY\fR
73 does not presently check whether the operator family definition includes all the operators and functions required by the index method, nor whether the operators and functions form a self\-consistent set\&. It is the user\*(Aqs responsibility to define a valid operator family\&.
74 .PP
75 Refer to
76 Section\ \&36.16
77 for further information\&.
78 .SH "PARAMETERS"
79 .PP
80 \fIname\fR
81 .RS 4
82 The name (optionally schema\-qualified) of an existing operator family\&.
83 .RE
84 .PP
85 \fIindex_method\fR
86 .RS 4
87 The name of the index method this operator family is for\&.
88 .RE
89 .PP
90 \fIstrategy_number\fR
91 .RS 4
92 The index method\*(Aqs strategy number for an operator associated with the operator family\&.
93 .RE
94 .PP
95 \fIoperator_name\fR
96 .RS 4
97 The name (optionally schema\-qualified) of an operator associated with the operator family\&.
98 .RE
99 .PP
100 \fIop_type\fR
101 .RS 4
102 In an
103 OPERATOR
104 clause, the operand data type(s) of the operator, or
105 NONE
106 to signify a prefix operator\&. Unlike the comparable syntax in
107 \fBCREATE OPERATOR CLASS\fR, the operand data types must always be specified\&.
108 .sp
109 In an
110 ADD FUNCTION
111 clause, the operand data type(s) the function is intended to support, if different from the input data type(s) of the function\&. For B\-tree comparison functions and hash functions it is not necessary to specify
112 \fIop_type\fR
113 since the function\*(Aqs input data type(s) are always the correct ones to use\&. For B\-tree sort support functions, B\-Tree equal image functions, and all functions in GiST, SP\-GiST and GIN operator classes, it is necessary to specify the operand data type(s) the function is to be used with\&.
114 .sp
115 In a
116 DROP FUNCTION
117 clause, the operand data type(s) the function is intended to support must be specified\&.
118 .RE
119 .PP
120 \fIsort_family_name\fR
121 .RS 4
122 The name (optionally schema\-qualified) of an existing
123 btree
124 operator family that describes the sort ordering associated with an ordering operator\&.
125 .sp
126 If neither
127 FOR SEARCH
128 nor
129 FOR ORDER BY
130 is specified,
131 FOR SEARCH
132 is the default\&.
133 .RE
134 .PP
135 \fIsupport_number\fR
136 .RS 4
137 The index method\*(Aqs support function number for a function associated with the operator family\&.
138 .RE
139 .PP
140 \fIfunction_name\fR
141 .RS 4
142 The name (optionally schema\-qualified) of a function that is an index method support function for the operator family\&. If no argument list is specified, the name must be unique in its schema\&.
143 .RE
144 .PP
145 \fIargument_type\fR
146 .RS 4
147 The parameter data type(s) of the function\&.
148 .RE
149 .PP
150 \fInew_name\fR
151 .RS 4
152 The new name of the operator family\&.
153 .RE
154 .PP
155 \fInew_owner\fR
156 .RS 4
157 The new owner of the operator family\&.
158 .RE
159 .PP
160 \fInew_schema\fR
161 .RS 4
162 The new schema for the operator family\&.
163 .RE
164 .PP
165 The
166 OPERATOR
167 and
168 FUNCTION
169 clauses can appear in any order\&.
170 .SH "NOTES"
171 .PP
172 Notice that the
173 DROP
174 syntax only specifies the
175 \(lqslot\(rq
176 in the operator family, by strategy or support number and input data type(s)\&. The name of the operator or function occupying the slot is not mentioned\&. Also, for
177 DROP FUNCTION
178 the type(s) to specify are the input data type(s) the function is intended to support; for GiST, SP\-GiST and GIN indexes this might have nothing to do with the actual input argument types of the function\&.
179 .PP
180 Because the index machinery does not check access permissions on functions before using them, including a function or operator in an operator family is tantamount to granting public execute permission on it\&. This is usually not an issue for the sorts of functions that are useful in an operator family\&.
181 .PP
182 The operators should not be defined by SQL functions\&. An SQL function is likely to be inlined into the calling query, which will prevent the optimizer from recognizing that the query matches an index\&.
183 .SH "EXAMPLES"
184 .PP
185 The following example command adds cross\-data\-type operators and support functions to an operator family that already contains B\-tree operator classes for data types
186 int4
187 and
188 int2\&.
189 .sp
190 .if n \{\
191 .RS 4
192 .\}
193 .nf
194 ALTER OPERATOR FAMILY integer_ops USING btree ADD
195
196   \-\- int4 vs int2
197   OPERATOR 1 < (int4, int2) ,
198   OPERATOR 2 <= (int4, int2) ,
199   OPERATOR 3 = (int4, int2) ,
200   OPERATOR 4 >= (int4, int2) ,
201   OPERATOR 5 > (int4, int2) ,
202   FUNCTION 1 btint42cmp(int4, int2) ,
203
204   \-\- int2 vs int4
205   OPERATOR 1 < (int2, int4) ,
206   OPERATOR 2 <= (int2, int4) ,
207   OPERATOR 3 = (int2, int4) ,
208   OPERATOR 4 >= (int2, int4) ,
209   OPERATOR 5 > (int2, int4) ,
210   FUNCTION 1 btint24cmp(int2, int4) ;
211 .fi
212 .if n \{\
213 .RE
214 .\}
215 .PP
216 To remove these entries again:
217 .sp
218 .if n \{\
219 .RS 4
220 .\}
221 .nf
222 ALTER OPERATOR FAMILY integer_ops USING btree DROP
223
224   \-\- int4 vs int2
225   OPERATOR 1 (int4, int2) ,
226   OPERATOR 2 (int4, int2) ,
227   OPERATOR 3 (int4, int2) ,
228   OPERATOR 4 (int4, int2) ,
229   OPERATOR 5 (int4, int2) ,
230   FUNCTION 1 (int4, int2) ,
231
232   \-\- int2 vs int4
233   OPERATOR 1 (int2, int4) ,
234   OPERATOR 2 (int2, int4) ,
235   OPERATOR 3 (int2, int4) ,
236   OPERATOR 4 (int2, int4) ,
237   OPERATOR 5 (int2, int4) ,
238   FUNCTION 1 (int2, int4) ;
239 .fi
240 .if n \{\
241 .RE
242 .\}
243 .SH "COMPATIBILITY"
244 .PP
245 There is no
246 \fBALTER OPERATOR FAMILY\fR
247 statement in the SQL standard\&.
248 .SH "SEE ALSO"
249 CREATE OPERATOR FAMILY (\fBCREATE_OPERATOR_FAMILY\fR(7)), DROP OPERATOR FAMILY (\fBDROP_OPERATOR_FAMILY\fR(7)), CREATE OPERATOR CLASS (\fBCREATE_OPERATOR_CLASS\fR(7)), ALTER OPERATOR CLASS (\fBALTER_OPERATOR_CLASS\fR(7)), DROP OPERATOR CLASS (\fBDROP_OPERATOR_CLASS\fR(7))