File: sql-createoperator.html

package info (click to toggle)
pgadmin3 1.4.3-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 29,796 kB
  • ctags: 10,758
  • sloc: cpp: 55,356; sh: 6,164; ansic: 1,520; makefile: 576; sql: 482; xml: 100; perl: 18
file content (194 lines) | stat: -rw-r--r-- 9,788 bytes parent folder | download
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>CREATE OPERATOR</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-createlanguage.html" title="CREATE LANGUAGE">
<link rel="next" href="sql-createopclass.html" title="CREATE OPERATOR CLASS">
<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-createoperator"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2>Name</h2>
<p>CREATE OPERATOR &#8212; define a new operator</p>
</div>
<a name="id757804"></a><div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">CREATE OPERATOR <em class="replaceable"><code>name</code></em> (
    PROCEDURE = <em class="replaceable"><code>funcname</code></em>
    [, LEFTARG = <em class="replaceable"><code>lefttype</code></em> ] [, RIGHTARG = <em class="replaceable"><code>righttype</code></em> ]
    [, COMMUTATOR = <em class="replaceable"><code>com_op</code></em> ] [, NEGATOR = <em class="replaceable"><code>neg_op</code></em> ]
    [, RESTRICT = <em class="replaceable"><code>res_proc</code></em> ] [, JOIN = <em class="replaceable"><code>join_proc</code></em> ]
    [, HASHES ] [, MERGES ]
    [, SORT1 = <em class="replaceable"><code>left_sort_op</code></em> ] [, SORT2 = <em class="replaceable"><code>right_sort_op</code></em> ]
    [, LTCMP = <em class="replaceable"><code>less_than_op</code></em> ] [, GTCMP = <em class="replaceable"><code>greater_than_op</code></em> ]
)</pre>
</div>
<div class="refsect1" lang="en">
<a name="id757903"></a><h2>Description</h2>
<p>   <code class="command">CREATE OPERATOR</code> defines a new operator,
   <em class="replaceable"><code>name</code></em>.  The user who
   defines an operator becomes its owner.  If a schema name is given
   then the operator is created in the specified schema.  Otherwise it
   is created in the current schema.
  </p>
<p>   The operator name is a sequence of up to <code class="symbol">NAMEDATALEN</code>-1
   (63 by default) characters from the following list:
</p>
<div class="literallayout"><p>+-*/&lt;&gt;=~!@#%^&amp;|`?</p></div>
<p>

   There are a few restrictions on your choice of name:
   </p>
<div class="itemizedlist"><ul type="disc">
<li><p>     <code class="literal">--</code> and <code class="literal">/*</code> cannot appear anywhere in an operator name,
     since they will be taken as the start of a comment.
     </p></li>
<li>
<p>     A multicharacter operator name cannot end in <code class="literal">+</code> or
     <code class="literal">-</code>,
     unless the name also contains at least one of these characters:
</p>
<div class="literallayout"><p>~!@#%^&amp;|`?</p></div>
<p>
     For example, <code class="literal">@-</code> is an allowed operator name,
     but <code class="literal">*-</code> is not.
     This restriction allows <span class="productname">PostgreSQL</span> to
     parse SQL-compliant commands without requiring spaces between tokens.
     </p>
</li>
</ul></div>
<p>
  </p>
<p>   The operator <code class="literal">!=</code> is mapped to
   <code class="literal">&lt;&gt;</code> on input, so these two names are always
   equivalent.
  </p>
<p>   At least one of <code class="literal">LEFTARG</code> and <code class="literal">RIGHTARG</code> must be defined.  For
   binary operators, both must be defined. For right  unary
   operators, only <code class="literal">LEFTARG</code> should be defined, while for left
   unary operators only <code class="literal">RIGHTARG</code> should be defined.
  </p>
<p>   The <em class="replaceable"><code>funcname</code></em>
   procedure must have been previously defined using <code class="command">CREATE
   FUNCTION</code> and must be defined to accept the correct number
   of arguments (either one or two) of the indicated types.
  </p>
<p>   The other clauses specify optional operator optimization clauses.
   Their meaning is detailed in <a href="xoper-optimization.html" title="32.13.Operator Optimization Information">Section32.13, &#8220;Operator Optimization Information&#8221;</a>.
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id758097"></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 to be defined. See above for allowable
        characters.  The name may be schema-qualified, for example
        <code class="literal">CREATE OPERATOR myschema.+ (...)</code>.  If not, then
        the operator is created in the current schema.  Two operators
        in the same schema can have the same name if they operate on
        different data types.  This is called
        <em class="firstterm">overloading</em>.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>funcname</code></em></span></dt>
<dd><p>        The function used to implement this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>lefttype</code></em></span></dt>
<dd><p>        The data type of the operator's left operand, if any.
        This option would be omitted for a left-unary operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>righttype</code></em></span></dt>
<dd><p>        The data type of the operator's right operand, if any.
        This option would be omitted for a right-unary operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>com_op</code></em></span></dt>
<dd><p>        The commutator of this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>neg_op</code></em></span></dt>
<dd><p>        The negator of this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>res_proc</code></em></span></dt>
<dd><p>        The restriction selectivity estimator function for this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>join_proc</code></em></span></dt>
<dd><p>        The join selectivity estimator function for this operator.
       </p></dd>
<dt><span class="term"><code class="literal">HASHES</code></span></dt>
<dd><p>       Indicates this operator can support a hash join.
       </p></dd>
<dt><span class="term"><code class="literal">MERGES</code></span></dt>
<dd><p>       Indicates this operator can support a merge join.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>left_sort_op</code></em></span></dt>
<dd><p>        If this operator can support a merge join, the less-than
        operator that sorts the left-hand data type of this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>right_sort_op</code></em></span></dt>
<dd><p>        If this operator can support a merge join, the less-than
        operator that sorts the right-hand data type of this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>less_than_op</code></em></span></dt>
<dd><p>        If this operator can support a merge join, the less-than
        operator that compares the input data types of this operator.
       </p></dd>
<dt><span class="term"><em class="replaceable"><code>greater_than_op</code></em></span></dt>
<dd><p>        If this operator can support a merge join, the greater-than
        operator that compares the input data types of this operator.
       </p></dd>
</dl></div>
<p>   To give a schema-qualified operator name in <em class="replaceable"><code>com_op</code></em> or the other optional
   arguments, use the <code class="literal">OPERATOR()</code> syntax, for example
</p>
<pre class="programlisting">COMMUTATOR = OPERATOR(myschema.===) ,</pre>
<p>  
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id758326"></a><h2>Notes</h2>
<p>   Refer to <a href="xoper.html" title="32.12.User-Defined Operators">Section32.12, &#8220;User-Defined Operators&#8221;</a> for further information.
  </p>
<p>   Use <a href="sql-dropoperator.html">DROP OPERATOR</a> to delete user-defined operators
   from a database.  Use <a href="sql-alteroperator.html">ALTER OPERATOR</a> to modify operators in a
   database.
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id758367"></a><h2>Examples</h2>
<p>   The following command defines a new operator, area-equality, for
   the data type <code class="type">box</code>:
</p>
<pre class="programlisting">CREATE OPERATOR === (
    LEFTARG = box,
    RIGHTARG = box,
    PROCEDURE = area_equal_procedure,
    COMMUTATOR = ===,
    NEGATOR = !==,
    RESTRICT = area_restriction_procedure,
    JOIN = area_join_procedure,
    HASHES,
    SORT1 = &lt;&lt;&lt;,
    SORT2 = &lt;&lt;&lt;
    -- Since sort operators were given, MERGES is implied.
    -- LTCMP and GTCMP are assumed to be &lt; and &gt; respectively
);</pre>
<p>  
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id758393"></a><h2>Compatibility</h2>
<p>   <code class="command">CREATE OPERATOR</code> is a
   <span class="productname">PostgreSQL</span> extension.  There are no
   provisions for user-defined operators in the SQL standard.
  </p>
</div>
<div class="refsect1" lang="en">
<a name="id758414"></a><h2>See Also</h2>
<span class="simplelist"><a href="sql-alteroperator.html">ALTER OPERATOR</a>, <a href="sql-createopclass.html">CREATE OPERATOR CLASS</a>, <a href="sql-dropoperator.html">DROP OPERATOR</a></span>
</div>
</div></body>
</html>