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