1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.11 1999/07/22 15:09:08 thomas Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/create_operator.sgml,v 1.12 2000/03/18 18:03:12 tgl Exp $
3
3
Postgres documentation
4
4
-->
5
5
@@ -60,25 +60,25 @@ CREATE OPERATOR <replaceable>name</replaceable> ( PROCEDURE = <replaceable class
60
60
<term><replaceable class="parameter">type1</replaceable></term>
61
61
<listitem>
62
62
<para>
63
- The type for the left-hand side of the operator, if any. This option would be
64
- omitted for a right -unary operator.
63
+ The type of the left-hand argument of the operator, if any.
64
+ This option would be omitted for a left -unary operator.
65
65
</para>
66
66
</listitem>
67
67
</varlistentry>
68
68
<varlistentry>
69
69
<term><replaceable class="parameter">type2</replaceable></term>
70
70
<listitem>
71
71
<para>
72
- The type for the right-hand side of the operator, if any. This option would be
73
- omitted for a left -unary operator.
72
+ The type of the right-hand argument of the operator, if any.
73
+ This option would be omitted for a right -unary operator.
74
74
</para>
75
75
</listitem>
76
76
</varlistentry>
77
77
<varlistentry>
78
78
<term><replaceable class="parameter">com_op</replaceable></term>
79
79
<listitem>
80
80
<para>
81
- The commutator for this operator.
81
+ The commutator of this operator.
82
82
</para>
83
83
</listitem>
84
84
</varlistentry>
@@ -110,23 +110,25 @@ CREATE OPERATOR <replaceable>name</replaceable> ( PROCEDURE = <replaceable class
110
110
<term>HASHES</term>
111
111
<listitem>
112
112
<para>
113
- Indicates this operator can support a hash-join algorithm .
113
+ Indicates this operator can support a hash join .
114
114
</para>
115
115
</listitem>
116
116
</varlistentry>
117
117
<varlistentry>
118
118
<term><replaceable class="parameter">left_sort_op</replaceable></term>
119
119
<listitem>
120
120
<para>
121
- Operator that sorts the left-hand data type of this operator.
121
+ If this operator can support a merge join, the
122
+ operator that sorts the left-hand data type of this operator.
122
123
</para>
123
124
</listitem>
124
125
</varlistentry>
125
126
<varlistentry>
126
127
<term><replaceable class="parameter">right_sort_op</replaceable></term>
127
128
<listitem>
128
129
<para>
129
- Operator that sorts the right-hand data type of this operator.
130
+ If this operator can support a merge join, the
131
+ operator that sorts the right-hand data type of this operator.
130
132
</para>
131
133
</listitem>
132
134
</varlistentry>
@@ -172,22 +174,56 @@ CREATE
172
174
</para>
173
175
<para>
174
176
The operator <replaceable class="parameter">name</replaceable>
175
- is a sequence of up to thirty two (32) characters in any combination
176
- from the following:
177
+ is a sequence of up to NAMEDATALEN-1 (31 by default) characters
178
+ from the following list :
177
179
<literallayout>
178
- + - * / < > = ~ ! @ # % ^ & | ` ? $ :
180
+ + - * / < > = ~ ! @ # % ^ & | ` ? $ :
179
181
</literallayout>
182
+
183
+ There are a few restrictions on your choice of name:
184
+ <itemizedlist>
185
+ <listitem>
186
+ <para>
187
+ "$" and ":" cannot be defined as single-character operators,
188
+ although they can be part of a multi-character operator name.
189
+ </para>
190
+ </listitem>
191
+ <listitem>
192
+ <para>
193
+ "--" and "/*" cannot appear anywhere in an operator name,
194
+ since they will be taken as the start of a comment.
195
+ </para>
196
+ </listitem>
197
+ <listitem>
198
+ <para>
199
+ A multi-character operator name cannot end in "+" or "-",
200
+ unless the name also contains at least one of these characters:
201
+ <literallayout>
202
+ ~ ! @ # % ^ & | ` ? $ :
203
+ </literallayout>
204
+ For example, <literal>@-</literal> is an allowed operator name,
205
+ but <literal>*-</literal> is not.
206
+ This restriction allows <productname>Postgres</productname> to
207
+ parse SQL-compliant queries without requiring spaces between tokens.
208
+ </para>
209
+ </listitem>
210
+ </itemizedlist>
211
+
180
212
<note>
181
213
<para>
182
- No alphabetic characters are allowed in an operator name.
183
- This enables <productname>Postgres</productname> to parse SQL input
184
- into tokens without requiring spaces between each token.
214
+ When working with non-SQL-standard operator names, you will usually
215
+ need to separate adjacent operators with spaces to avoid ambiguity.
216
+ For example, if you have defined a left-unary operator named "@",
217
+ you cannot write <literal>X*@Y</literal>; you must write
218
+ <literal>X* @Y</literal> to ensure that
219
+ <productname>Postgres</productname> reads it as two operator names
220
+ not one.
185
221
</para>
186
222
</note>
187
223
</para>
188
224
<para>
189
- The operator "!=" is mapped to "<>" on input, so they are
190
- therefore equivalent.
225
+ The operator "!=" is mapped to "<>" on input, so these two names
226
+ are always equivalent.
191
227
</para>
192
228
<para>
193
229
At least one of LEFTARG and RIGHTARG must be defined. For
@@ -196,11 +232,11 @@ CREATE
196
232
unary operators only RIGHTARG should be defined.
197
233
</para>
198
234
<para>
199
- Also, the
235
+ The
200
236
<replaceable class="parameter">func_name</replaceable> procedure must have
201
237
been previously defined using <command>CREATE FUNCTION</command> and must
202
238
be defined to accept the correct number of arguments
203
- (either one or two).
239
+ (either one or two) of the indicated types .
204
240
</para>
205
241
<para>
206
242
The commutator operator should be identified if one exists,
@@ -247,8 +283,6 @@ MYBOXES.description !== "0,0,1,1"::box
247
283
does not yet have a commutator itself, then the commutator's
248
284
entry is updated to have the newly created operator as its
249
285
commutator. This applies to the negator, as well.
250
- </para>
251
- <para>
252
286
This is to allow the definition of two operators that are
253
287
the commutators or the negators of each other. The first
254
288
operator should be defined without a commutator or negator
@@ -258,7 +292,7 @@ MYBOXES.description !== "0,0,1,1"::box
258
292
it also works to just have both operators refer to each other.)
259
293
</para>
260
294
<para>
261
- The next three specifications are present to support the
295
+ The HASHES, SORT1, and SORT2 options are present to support the
262
296
query optimizer in performing joins.
263
297
<productname>Postgres</productname> can always
264
298
evaluate a join (i.e., processing a clause with two tuple
@@ -294,9 +328,8 @@ MYBOXES.description !== "0,0,1,1"::box
294
328
be worth the complexity involved.
295
329
</para>
296
330
<para>
297
- The last two pieces of the specification are present so
298
- the query optimizer can estimate result sizes. If a
299
- clause of the form:
331
+ The RESTRICT and JOIN options assist the query optimizer in estimating
332
+ result sizes. If a clause of the form:
300
333
<programlisting>
301
334
MYBOXES.description <<< "0,0,1,1"::box
302
335
</programlisting>
@@ -310,15 +343,15 @@ MYBOXES.description <<< "0,0,1,1"::box
310
343
data types and returns a floating point number. The
311
344
query optimizer simply calls this function, passing the
312
345
parameter "0,0,1,1" and multiplies the result by the relation
313
- size to get the desired expected number of instances.
346
+ size to get the expected number of instances.
314
347
</para>
315
348
<para>
316
349
Similarly, when the operands of the operator both contain
317
350
instance variables, the query optimizer must estimate the
318
351
size of the resulting join. The function join_proc will
319
352
return another floating point number which will be multiplied
320
353
by the cardinalities of the two classes involved to
321
- compute the desired expected result size.
354
+ compute the expected result size.
322
355
</para>
323
356
<para>
324
357
The difference between the function
0 commit comments