CREATE OPERATOR

This page documents the preview version (v2.21). Preview includes features under active development and is for development and testing only. For production, use the stable version (v2024.1). To learn more, see Versioning.

Synopsis

Use the CREATE OPERATOR statement to create an operator.

Syntax

create_operator ::= CREATE OPERATOR operator_name  ( 
                    { FUNCTION = subprogram_name
                      | PROCEDURE = subprogram_name } 
                    [ , operator_option [ ... ] ] )

operator_option ::= LEFTARG = left_type
                    | RIGHTARG = right_type
                    | COMMUTATOR = com_op
                    | NEGATOR = neg_op
                    | RESTRICT = res_proc
                    | JOIN = join_proc
                    | HASHES
                    | MERGES

create_operator

CREATEOPERATORoperator_name(FUNCTION=subprogram_namePROCEDURE=subprogram_name,operator_option)

operator_option

LEFTARG=left_typeRIGHTARG=right_typeCOMMUTATOR=com_opNEGATOR=neg_opRESTRICT=res_procJOIN=join_procHASHESMERGES

Semantics

See the semantics of each option in the [PostgreSQL docs][postgresql-docs-create-operator].

Examples

Basic example.

yugabyte=# CREATE OPERATOR @#@ (
             rightarg = int8,
             procedure = numeric_fac
           );
yugabyte=# SELECT @#@ 5;
 ?column?
----------
      120

See also