1CREATE OPERATOR(7) PostgreSQL 10.7 Documentation CREATE OPERATOR(7)
2
3
4
6 CREATE_OPERATOR - define a new operator
7
9 CREATE OPERATOR name (
10 PROCEDURE = function_name
11 [, LEFTARG = left_type ] [, RIGHTARG = right_type ]
12 [, COMMUTATOR = com_op ] [, NEGATOR = neg_op ]
13 [, RESTRICT = res_proc ] [, JOIN = join_proc ]
14 [, HASHES ] [, MERGES ]
15 )
16
18 CREATE OPERATOR defines a new operator, name. The user who defines an
19 operator becomes its owner. If a schema name is given then the operator
20 is created in the specified schema. Otherwise it is created in the
21 current schema.
22
23 The operator name is a sequence of up to NAMEDATALEN-1 (63 by default)
24 characters from the following list:
25
26 + - * / < > = ~ ! @ # % ^ & | ` ?
27
28 There are a few restrictions on your choice of name:
29
30 · -- and /* cannot appear anywhere in an operator name, since they
31 will be taken as the start of a comment.
32
33 · A multicharacter operator name cannot end in + or -, unless the
34 name also contains at least one of these characters:
35
36 ~ ! @ # % ^ & | ` ?
37
38 For example, @- is an allowed operator name, but *- is not. This
39 restriction allows PostgreSQL to parse SQL-compliant commands
40 without requiring spaces between tokens.
41
42 · The use of => as an operator name is deprecated. It may be
43 disallowed altogether in a future release.
44
45 The operator != is mapped to <> on input, so these two names are always
46 equivalent.
47
48 At least one of LEFTARG and RIGHTARG must be defined. For binary
49 operators, both must be defined. For right unary operators, only
50 LEFTARG should be defined, while for left unary operators only RIGHTARG
51 should be defined.
52
53 The function_name procedure must have been previously defined using
54 CREATE FUNCTION and must be defined to accept the correct number of
55 arguments (either one or two) of the indicated types.
56
57 The other clauses specify optional operator optimization clauses. Their
58 meaning is detailed in Section 37.13.
59
60 To be able to create an operator, you must have USAGE privilege on the
61 argument types and the return type, as well as EXECUTE privilege on the
62 underlying function. If a commutator or negator operator is specified,
63 you must own these operators.
64
66 name
67 The name of the operator to be defined. See above for allowable
68 characters. The name can be schema-qualified, for example CREATE
69 OPERATOR myschema.+ (...). If not, then the operator is created in
70 the current schema. Two operators in the same schema can have the
71 same name if they operate on different data types. This is called
72 overloading.
73
74 function_name
75 The function used to implement this operator.
76
77 left_type
78 The data type of the operator's left operand, if any. This option
79 would be omitted for a left-unary operator.
80
81 right_type
82 The data type of the operator's right operand, if any. This option
83 would be omitted for a right-unary operator.
84
85 com_op
86 The commutator of this operator.
87
88 neg_op
89 The negator of this operator.
90
91 res_proc
92 The restriction selectivity estimator function for this operator.
93
94 join_proc
95 The join selectivity estimator function for this operator.
96
97 HASHES
98 Indicates this operator can support a hash join.
99
100 MERGES
101 Indicates this operator can support a merge join.
102
103 To give a schema-qualified operator name in com_op or the other
104 optional arguments, use the OPERATOR() syntax, for example:
105
106 COMMUTATOR = OPERATOR(myschema.===) ,
107
109 Refer to Section 37.12 for further information.
110
111 It is not possible to specify an operator's lexical precedence in
112 CREATE OPERATOR, because the parser's precedence behavior is
113 hard-wired. See Section 4.1.6 for precedence details.
114
115 The obsolete options SORT1, SORT2, LTCMP, and GTCMP were formerly used
116 to specify the names of sort operators associated with a merge-joinable
117 operator. This is no longer necessary, since information about
118 associated operators is found by looking at B-tree operator families
119 instead. If one of these options is given, it is ignored except for
120 implicitly setting MERGES true.
121
122 Use DROP OPERATOR (DROP_OPERATOR(7)) to delete user-defined operators
123 from a database. Use ALTER OPERATOR (ALTER_OPERATOR(7)) to modify
124 operators in a database.
125
127 The following command defines a new operator, area-equality, for the
128 data type box:
129
130 CREATE OPERATOR === (
131 LEFTARG = box,
132 RIGHTARG = box,
133 PROCEDURE = area_equal_procedure,
134 COMMUTATOR = ===,
135 NEGATOR = !==,
136 RESTRICT = area_restriction_procedure,
137 JOIN = area_join_procedure,
138 HASHES, MERGES
139 );
140
142 CREATE OPERATOR is a PostgreSQL extension. There are no provisions for
143 user-defined operators in the SQL standard.
144
146 ALTER OPERATOR (ALTER_OPERATOR(7)), CREATE OPERATOR CLASS
147 (CREATE_OPERATOR_CLASS(7)), DROP OPERATOR (DROP_OPERATOR(7))
148
149
150
151PostgreSQL 10.7 2019 CREATE OPERATOR(7)