postgresql_16:7.1.70.1 Description
PostgreSQL 16 > Reference > SQL Commands > CREATE OPERATOR > Description
CREATE OPERATOR defines a new operator, *name*. 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.
The operator name is a sequence of up to NAMEDATALEN-1 (63 by default) characters from the following list: + - * / < > = ~ ! @ # % ^ & | ? There are a few restrictions on your choice of name: -- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment. A multicharacter operator name cannot end in + or -, unless the name also contains at least one of these characters: ~ ! @ # % ^ & | ? For example, @- is an allowed operator name, but *- is not. This restriction allows PostgreSQL to parse SQL-compliant commands without requiring spaces between tokens. The symbol => is reserved by the SQL grammar, so it cannot be used as an operator name.
The operator != is mapped to <> on input, so these two names are always equivalent.
For binary operators, both LEFTARG and RIGHTARG must be defined. For prefix operators only RIGHTARG should be defined. The *function_name* function must have been previously defined using CREATE FUNCTION and must be defined to accept the correct number of arguments (either one or two) of the indicated types.
In the syntax of CREATE OPERATOR, the keywords FUNCTION and PROCEDURE are equivalent, but the referenced function must in any case be a function, not a procedure. The use of the keyword PROCEDURE here is historical and deprecated.
The other clauses specify optional operator optimization clauses. Their meaning is detailed in (see postgresql_16:6.1.15).
To be able to create an operator, you must have USAGE privilege on the argument types and the return type, as well as EXECUTE privilege on the underlying function. If a commutator or negator operator is specified, you must own these operators.