CREATE OPERATOR name (
- PROCEDURE = function_name
+ {FUNCTION|PROCEDURE} = function_name
[, LEFTARG = left_type ] [, RIGHTARG = right_type ]
[, COMMUTATOR = com_op ] [, NEGATOR = neg_op ]
[, RESTRICT = res_proc ] [, JOIN = join_proc ]
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 .
CREATE OPERATOR === (
LEFTARG = box,
RIGHTARG = box,
- PROCEDURE = area_equal_function,
+ FUNCTION = area_equal_function,
COMMUTATOR = ===,
NEGATOR = !==,
RESTRICT = area_restriction_function,
CREATE OPERATOR + (
leftarg = complex,
rightarg = complex,
- procedure = complex_add,
+ function = complex_add,
commutator = +
);
We've shown how to create a binary operator here. To create unary
operators, just omit one of leftarg (for left unary) or
- rightarg (for right unary). The procedure
+ rightarg (for right unary). The function
clause and the argument clauses are the only required items in
CREATE OPERATOR. The commutator
clause shown in the example is an optional hint to the query
* NOTES
* These things must be defined and committed in the following order:
* "create function":
- * input/output, recv/send procedures
+ * input/output, recv/send functions
* "create type":
* type
* "create operator":
Oid rettype;
List *commutatorName = NIL; /* optional commutator operator name */
List *negatorName = NIL; /* optional negator operator name */
- List *restrictionName = NIL; /* optional restrict. sel. procedure */
- List *joinName = NIL; /* optional join sel. procedure */
+ List *restrictionName = NIL; /* optional restrict. sel. function */
+ List *joinName = NIL; /* optional join sel. function */
Oid functionOid; /* functions converted to OID */
Oid restrictionOid;
Oid joinOid;
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
errmsg("SETOF type not allowed for operator argument")));
}
+ /* "function" and "procedure" are equivalent here */
+ else if (strcmp(defel->defname, "function") == 0)
+ functionName = defGetQualifiedName(defel);
else if (strcmp(defel->defname, "procedure") == 0)
functionName = defGetQualifiedName(defel);
else if (strcmp(defel->defname, "commutator") == 0)
if (functionName == NIL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
- errmsg("operator procedure must be specified")));
+ errmsg("operator function must be specified")));
/* Transform type names to type OIDs */
if (typeName1)
functionOid, /* function for operator */
commutatorName, /* optional commutator operator name */
negatorName, /* optional negator operator name */
- restrictionOid, /* optional restrict. sel. procedure */
- joinOid, /* optional join sel. procedure name */
+ restrictionOid, /* optional restrict. sel. function */
+ joinOid, /* optional join sel. function name */
canMerge, /* operator merges */
canHash); /* operator hashes */
}
Datum values[Natts_pg_operator];
bool nulls[Natts_pg_operator];
bool replaces[Natts_pg_operator];
- List *restrictionName = NIL; /* optional restrict. sel. procedure */
+ List *restrictionName = NIL; /* optional restrict. sel. function */
bool updateRestriction = false;
Oid restrictionOid;
- List *joinName = NIL; /* optional join sel. procedure */
+ List *joinName = NIL; /* optional join sel. function */
bool updateJoin = false;
Oid joinOid;
*/
else if (strcmp(defel->defname, "leftarg") == 0 ||
strcmp(defel->defname, "rightarg") == 0 ||
+ strcmp(defel->defname, "function") == 0 ||
strcmp(defel->defname, "procedure") == 0 ||
strcmp(defel->defname, "commutator") == 0 ||
strcmp(defel->defname, "negator") == 0 ||