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

NAME

6       CREATE_OPERATOR - define a new operator
7

SYNOPSIS

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

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 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 35.13, “Operator Optimization
59       Information”, in the documentation.
60
61       To be able to create an operator, you must have USAGE privilege on the
62       argument types and the return type, as well as EXECUTE privilege on the
63       underlying function. If a commutator or negator operator is specified,
64       you must own these operators.
65

PARAMETERS

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

NOTES

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

EXAMPLES

130       The following command defines a new operator, area-equality, for the
131       data type box:
132
133           CREATE OPERATOR === (
134               LEFTARG = box,
135               RIGHTARG = box,
136               PROCEDURE = area_equal_procedure,
137               COMMUTATOR = ===,
138               NEGATOR = !==,
139               RESTRICT = area_restriction_procedure,
140               JOIN = area_join_procedure,
141               HASHES, MERGES
142           );
143

COMPATIBILITY

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

SEE ALSO

149       ALTER OPERATOR (ALTER_OPERATOR(7)), CREATE OPERATOR CLASS
150       (CREATE_OPERATOR_CLASS(7)), DROP OPERATOR (DROP_OPERATOR(7))
151
152
153
154PostgreSQL 9.2.24                 2017-11-06                CREATE OPERATOR(7)
Impressum