1CREATE OPERATOR(7)       PostgreSQL 12.2 Documentation      CREATE OPERATOR(7)
2
3
4

NAME

6       CREATE_OPERATOR - define a new operator
7

SYNOPSIS

9       CREATE OPERATOR name (
10           {FUNCTION|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

DESCRIPTION

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 function 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       In the syntax of CREATE OPERATOR, the keywords FUNCTION and PROCEDURE
58       are equivalent, but the referenced function must in any case be a
59       function, not a procedure. The use of the keyword PROCEDURE here is
60       historical and deprecated.
61
62       The other clauses specify optional operator optimization clauses. Their
63       meaning is detailed in Section 37.15.
64
65       To be able to create an operator, you must have USAGE privilege on the
66       argument types and the return type, as well as EXECUTE privilege on the
67       underlying function. If a commutator or negator operator is specified,
68       you must own these operators.
69

PARAMETERS

71       name
72           The name of the operator to be defined. See above for allowable
73           characters. The name can be schema-qualified, for example CREATE
74           OPERATOR myschema.+ (...). If not, then the operator is created in
75           the current schema. Two operators in the same schema can have the
76           same name if they operate on different data types. This is called
77           overloading.
78
79       function_name
80           The function used to implement this operator.
81
82       left_type
83           The data type of the operator's left operand, if any. This option
84           would be omitted for a left-unary operator.
85
86       right_type
87           The data type of the operator's right operand, if any. This option
88           would be omitted for a right-unary operator.
89
90       com_op
91           The commutator of this operator.
92
93       neg_op
94           The negator of this operator.
95
96       res_proc
97           The restriction selectivity estimator function for this operator.
98
99       join_proc
100           The join selectivity estimator function for this operator.
101
102       HASHES
103           Indicates this operator can support a hash join.
104
105       MERGES
106           Indicates this operator can support a merge join.
107
108       To give a schema-qualified operator name in com_op or the other
109       optional arguments, use the OPERATOR() syntax, for example:
110
111           COMMUTATOR = OPERATOR(myschema.===) ,
112

NOTES

114       Refer to Section 37.14 for further information.
115
116       It is not possible to specify an operator's lexical precedence in
117       CREATE OPERATOR, because the parser's precedence behavior is
118       hard-wired. See Section 4.1.6 for precedence details.
119
120       The obsolete options SORT1, SORT2, LTCMP, and GTCMP were formerly used
121       to specify the names of sort operators associated with a merge-joinable
122       operator. This is no longer necessary, since information about
123       associated operators is found by looking at B-tree operator families
124       instead. If one of these options is given, it is ignored except for
125       implicitly setting MERGES true.
126
127       Use DROP OPERATOR (DROP_OPERATOR(7)) to delete user-defined operators
128       from a database. Use ALTER OPERATOR (ALTER_OPERATOR(7)) to modify
129       operators in a database.
130

EXAMPLES

132       The following command defines a new operator, area-equality, for the
133       data type box:
134
135           CREATE OPERATOR === (
136               LEFTARG = box,
137               RIGHTARG = box,
138               FUNCTION = area_equal_function,
139               COMMUTATOR = ===,
140               NEGATOR = !==,
141               RESTRICT = area_restriction_function,
142               JOIN = area_join_function,
143               HASHES, MERGES
144           );
145

COMPATIBILITY

147       CREATE OPERATOR is a PostgreSQL extension. There are no provisions for
148       user-defined operators in the SQL standard.
149

SEE ALSO

151       ALTER OPERATOR (ALTER_OPERATOR(7)), CREATE OPERATOR CLASS
152       (CREATE_OPERATOR_CLASS(7)), DROP OPERATOR (DROP_OPERATOR(7))
153
154
155
156PostgreSQL 12.2                      2020                   CREATE OPERATOR(7)
Impressum